From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83CA4C433DF for ; Sun, 18 Oct 2020 16:59:49 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2C33A2222B for ; Sun, 18 Oct 2020 16:59:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="yiG1Yv0N"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fvbVbd6b" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2C33A2222B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type:Cc: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=VRDiOoWbPsHwOC80qAxW//uOq1miZR3RuIcrky5x5+c=; b=yiG1Yv0N6HhKjPie4zhUW9nM1 in3ywj6BVfHcT8RN8lnJicpuIlo5Gec29z6XDRin30p+Wnw8VBwCycrfW+ISX0zlXCJya70Kgzgi5 fYmkYNkRuTsmdd40uEwcimpa1fMV/tgdO8McpFYyojHdBe2oYGAmxBqOIZzE9U6VJz20ADK/e4rPd YKCeGdA5iWANRjyQ8/phOpDpwQDVRkqnvBuKCkbMv32Y32U1oZ8FrCrYHjVAatiCsEYumIbFZBvnX soB73940jbeuoZAaHCRuOjdVrn0DPx1Z+hQOZ37jRkOM19l3t9WbH75RT0cwjju5W1Gc9nUXo6qgI adKPDdj8Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kUC0r-00049A-Py; Sun, 18 Oct 2020 16:58:29 +0000 Received: from mail-qv1-xf43.google.com ([2607:f8b0:4864:20::f43]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kUC0p-00048b-JE for linux-arm-kernel@lists.infradead.org; Sun, 18 Oct 2020 16:58:28 +0000 Received: by mail-qv1-xf43.google.com with SMTP id g13so2832102qvu.1 for ; Sun, 18 Oct 2020 09:58:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=HJanRkOnYDRWWUUxMT+SX3xeE/WoWNZDclqoOIIZ6ik=; b=fvbVbd6bP0z7Vuuq+jqTEeUxxfKwXFaectxEGgR9FBXrWbQRPTqxDDp12hv7pyjgny pVkvJW2CkducvZ6zcT1Qg0RHQcsGRQ0FhijtX46wCeavXfhFRtyCnOyLjRs5MWQ9WPvQ gg5G9PlVyumf0QRB680kMp51sPQ6IHY4uqL2GYT6DCGRgnVz0RzxExcK+XR6LftDCd0U YJFevQR8R/XSy5mGZ+5t5z5pBJ23cZlNqC/oAw11/HkRs75AFqDH8WxVaKZqsErwqASc TwBvFGoV/fp1AX7pspMG1+psZXZFyGFkHafZmjY71NNHWOOGsyPr7xn5psISVrrjxveJ xJsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=HJanRkOnYDRWWUUxMT+SX3xeE/WoWNZDclqoOIIZ6ik=; b=CklJdTybgDqbc2E7DGLQAE1iVKj8ArIha46ClUHhpQqrE52ieWI4V/ZKq7Uu7ULY9e 4kKkurhgNcjFId4Y5OEUeqeKZisWJRB9VGRvBtxMrnPdIPLzflypHQcsY9dj7EQj2ClP nvF3g22JL5WfovWog9WwCYPL21AZnus8yO+2lGr/QedsGsWI8t9cZKs0xPZucjnY5z7z 32GEF47Pf3xLRbCAuGOmgFDoXTWeN4UN5WVzCwEXzqST2J5jftDjIPdhsSbYinbx5oa3 UMPeIBdLhmllc+PyFpx+mZW6ahKoejUh8fmBje4V+dL4vQQXPqa2FxuwBiVTxmIBR5mG 7VjQ== X-Gm-Message-State: AOAM530Hch4fj+PWzI5iwYMsaRkR9IG3Uk9eTayKLWUffA/dZOTmObU3 sN16aG9wxKec4CHOwC3q4/c= X-Google-Smtp-Source: ABdhPJxjcZwbX9ypE+uUB13PJDlMX4ZiI7bkB4E/9sDUMmaq7Hljo6yZcmPmqM5wbZ5FOb82iKUy0w== X-Received: by 2002:ad4:43e5:: with SMTP id f5mr13696233qvu.12.1603040305761; Sun, 18 Oct 2020 09:58:25 -0700 (PDT) Received: from shinobu (072-189-064-225.res.spectrum.com. [72.189.64.225]) by smtp.gmail.com with ESMTPSA id g5sm3325325qto.39.2020.10.18.09.58.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Oct 2020 09:58:24 -0700 (PDT) Date: Sun, 18 Oct 2020 12:58:22 -0400 From: William Breathitt Gray To: David Lechner Subject: Re: [PATCH v5 3/5] counter: Add character device interface Message-ID: <20201018165822.GE231549@shinobu> References: <00be1fccc672c5207f3b04fe4cc09c29e22641f4.1601170670.git.vilhelm.gray@gmail.com> MIME-Version: 1.0 In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201018_125827_654889_6BB7DCC3 X-CRM114-Status: GOOD ( 18.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kamel.bouhara@bootlin.com, gwendal@chromium.org, alexandre.torgue@st.com, linux-iio@vger.kernel.org, patrick.havelange@essensium.com, alexandre.belloni@bootlin.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, mcoquelin.stm32@gmail.com, syednwaris@gmail.com, linux-stm32@st-md-mailman.stormreply.com, jic23@kernel.org Content-Type: multipart/mixed; boundary="===============0166847184848316515==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============0166847184848316515== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="idY8LE8SD6/8DnRI" Content-Disposition: inline --idY8LE8SD6/8DnRI Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Oct 14, 2020 at 05:40:44PM -0500, David Lechner wrote: > On 9/26/20 9:18 PM, William Breathitt Gray wrote: > > +static ssize_t counter_chrdev_read(struct file *filp, char __user *buf, > > + size_t len, loff_t *f_ps) > > +{ > > + struct counter_device *const counter =3D filp->private_data; > > + int err; > > + unsigned long flags; > > + unsigned int copied; > > + > > + if (len < sizeof(struct counter_event)) > > + return -EINVAL; > > + > > + do { > > + if (kfifo_is_empty(&counter->events)) { > > + if (filp->f_flags & O_NONBLOCK) > > + return -EAGAIN; > > + > > + err =3D wait_event_interruptible(counter->events_wait, > > + !kfifo_is_empty(&counter->events)); > > + if (err) > > + return err; > > + } > > + > > + raw_spin_lock_irqsave(&counter->events_lock, flags); > > + err =3D kfifo_to_user(&counter->events, buf, len, &copied); > > + raw_spin_unlock_irqrestore(&counter->events_lock, flags); > > + if (err) > > + return err; > > + } while (!copied); > > + > > + return copied; > > +} >=20 > All other uses of kfifo_to_user() I saw use a mutex instead of spin > lock. I don't see a reason for disabling interrupts here. The Counter character device interface is special in this case because counter->events could be accessed from an interrupt context. This is possible if counter_push_event() is called for an interrupt (as is the case for the 104_quad_8 driver). In this case, we can't use mutex because we can't sleep in an interrupt context, so our only option is to use spin lock. William Breathitt Gray --idY8LE8SD6/8DnRI Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEk5I4PDJ2w1cDf/bghvpINdm7VJIFAl+MdC4ACgkQhvpINdm7 VJKtZA/+NKz/zDPUYG1k3eRF+qrTFSszN6ZaQVFDVW2dNUUxCvZtcCZ8x2hZx/n9 1hWhczCgYYpeYM6ahWC+JRwebm1vUqc/U3KbKRXVpJVg4dot5+A9jqiXtevPA99D RctZMaJLJ/1UGh2R4Pkiew5YtStfcqMlblDrIBCZiwCEY5mIs+6kR0CgaQUwG/sx M777scU4ixIM+o5m6XJoLkgh9Lv89KnESESl/XBBYXfcN7zYBXtEcmf4ixQhuO+Y ehpfmgpCcuBhrOVYjqzDN4h+dopSUVpI8QzTTe9Rpu8FgpoONnPm9O5cpD2rFvlL AVCEi9U+OCkiWvh5WozChmBVSkvnzRgQe6y2silU47bGfFumj9LSgb/QMLKNCXpz VgI4psvFiUPq17+PMXeNUH3+1v5FEaVjOQ1gBgl1Er9KPP2u9ixifrTkkssBzFAI luF4Z0nsEkK+ezF5oDT1IlSIZILChd8Lb2IGkXSebNQ/SQ2bAom+QNd8Spo1tIJR C2inE32wpPyUniISW+Hl6rxjM/uUKYiUh6WPjYx98u4tCrcHkBtZ5N3Pq59HrS5s tD6kyEScmGR+R/x6uvkdkgxSRSScFItkDFI8fo6765W3Fb7GAK9B8Clt//SMxgct NJDo7dKl/bsALJyLe2s/bHJNteD0o5S0jlU8fedIrB819/lqF54= =oUCr -----END PGP SIGNATURE----- --idY8LE8SD6/8DnRI-- --===============0166847184848316515== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============0166847184848316515==--