Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1931313ybh; Fri, 13 Mar 2020 09:53:39 -0700 (PDT) X-Google-Smtp-Source: ADFU+vthZuWuziI21jWAleCkIf544CMoB5FE0HWqf6Nz1qe2jkWPAW5AIfzCAMKymIGUC2TxvJl3 X-Received: by 2002:a9d:4b0c:: with SMTP id q12mr12517264otf.77.1584118419764; Fri, 13 Mar 2020 09:53:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584118419; cv=none; d=google.com; s=arc-20160816; b=WbhtTEW9bY3f0qK1BJx1KYHbVzJKsYsgbcCNLCxOHGmH+o+48igb4YORhN0+yEhvlF cwFFyeH73Aql8Lxi6qh/BZyShPZBtCVCRnb04Sg5SGU/hAm9pd8KitsDcZ2qCDb76K4J 8N52gMcvwxiz5i1ln7h5YjP+d05Cw0Xn4XHrsH/8eHb8qWo2a21LjWtd8L5ETJ1i7MmN 7dNEGJ+qWTTSs1Xus25+DLPJ2utKlaIgFxG4Ai7DnqII27hHVZaFNkuu+z0KWJjqPnQg 5Rwo+J2cY9dJAru6CtpIKfq4YJOnduiVgJYQqLlESep5H0ntSTMyOH8NLG+hF8qb8Vhk RspA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=zjrGKOmUu95Kp+WH+bIMTt0FHzvlrNH5EQNM4TLTqds=; b=BzGqL0ZsZgWDR18n2spnNq69fQCckmKtzBMtX1E+gtw6CPMYzgkoqPs3PRE+eGLlbq 441S3KiyxQ+py3bfmssFUAVCkoYIfZ69gFZQ/yiCPKC3kdnDlEmFpHIs/UnZ+lWCV0cQ byKOR6fySzQwmSH4NV8khdaTma3pLvdKknjeiGyBgqEfOkBxAOEc2nXpIx0tqUdGQK51 VTgLL1x+vOtMI0/X63bG7JSG68C3/wyQGKLuDP45Nnta8OIs1UApBjAIdMmqAhSVRI3u /YmatB4p1OaXTvaHNaMqUalZTZM5kNQ5jBEDTPflu0ZI5zJk0l4psygVSeXirrSW+67n AJsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Qp4bLpv8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i24si4939801otp.282.2020.03.13.09.53.27; Fri, 13 Mar 2020 09:53:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Qp4bLpv8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727064AbgCMQvl (ORCPT + 99 others); Fri, 13 Mar 2020 12:51:41 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:34256 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726526AbgCMQvl (ORCPT ); Fri, 13 Mar 2020 12:51:41 -0400 Received: by mail-qt1-f196.google.com with SMTP id 59so8064403qtb.1; Fri, 13 Mar 2020 09:51:40 -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=zjrGKOmUu95Kp+WH+bIMTt0FHzvlrNH5EQNM4TLTqds=; b=Qp4bLpv8axxeOXYJ8lXkTbS2Aa+dk1529QySUKA2lxUTfLuCBjYya1tMYAfmBEqGWn 4iFhwoD90MpUM0av/XEoHlfzM8THzxSTPAcgBx5Zv1EIVkV0dWRU3aYJ1daC8qCXxbX+ 0iTNzUFhFkXkC66oG7ciBlT735JUVEysHy+ZMZ4ZMn1aX/xQZRKh/N8FPLK2O2ol256Q iAbnPzJi9O0IzTVfqXk6jg+/xsB7QETVQz48Cvj9AyVhG1l+f6cZUf4JNY3XTWIt0R79 zEqmbuAWfcodyGnCCbdOmW9QHyDMjxybYo/n6S/7jy0r5qaPHjhpEHrNY6D8GkfQj03h rBmw== 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=zjrGKOmUu95Kp+WH+bIMTt0FHzvlrNH5EQNM4TLTqds=; b=Q2ubuEghtOHY5OK4d0ifIi/H65uDvyQZutahCTUPQnmq9JaX9nJ5xoiLnPUd9X4lqJ c0lYAes5x8UaDTUyUsPyWLRWAOy3EumMzZ70p7RAxzKk+blnYhQx1eLZElQ8xS1HOcy9 OjAXpot3TQoEXsZEsGI900lwMaZ1bZqbacPrK17JLcJP7nZYLQxhLJ8VrZ7jzzOPsnXh AMiomftk+0G8xcsfwkY/F0uG/xZQMSQNsokau5pItPhiChrVxCQqoNGMed5otebp4wGH y+hJ+XCDzawUtL/5J1bBnGFGmgI6cMOSBqlK5G0tCutPMwATKmzdiIhXERZWZtmy+arq KkgQ== X-Gm-Message-State: ANhLgQ1tbdeC9Faayi4TxhxtmAePnWBaD6r7edXC66pGJvvyjUCYzkzj tYhZ3qBARXTWhinG+PbNmBU= X-Received: by 2002:ac8:4548:: with SMTP id z8mr13902106qtn.188.1584118299979; Fri, 13 Mar 2020 09:51:39 -0700 (PDT) Received: from icarus (072-189-064-225.res.spectrum.com. [72.189.64.225]) by smtp.gmail.com with ESMTPSA id 82sm13610930qkd.62.2020.03.13.09.51.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Mar 2020 09:51:38 -0700 (PDT) Date: Fri, 13 Mar 2020 12:51:36 -0400 From: William Breathitt Gray To: Syed Nayyar Waris Cc: jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 2/3] counter: 104-quad-8: Add lock guards - differential encoder cable Message-ID: <20200313165136.GB5024@icarus> References: <20200313120133.GA17830@syed> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="b5gNqxB1S1yM7hjW" Content-Disposition: inline In-Reply-To: <20200313120133.GA17830@syed> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --b5gNqxB1S1yM7hjW Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Mar 13, 2020 at 05:31:33PM +0530, Syed Nayyar Waris wrote: > Add lock protection from race conditions in the 104-quad-8 counter > driver for differential encoder cable status changes. There is no IRQ > handling so use spin_lock calls for protection. >=20 > Fixes: bbef69e088c3 ("counter: 104-quad-8: Support Differential Encoder C= able Status") >=20 > Signed-off-by: Syed Nayyar Waris Signed-off-by: William Breathitt Gray > --- > Changes in v4: > - Shift review-comments section so that it is not saved in commit messag= e. > - Add spin_unlock calls for deadlock avoidance. > - Few changes related to casting. >=20 > drivers/counter/104-quad-8.c | 18 +++++++++++++++--- > 1 file changed, 15 insertions(+), 3 deletions(-) >=20 > diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c > index 9dab190..c9e227f 100644 > --- a/drivers/counter/104-quad-8.c > +++ b/drivers/counter/104-quad-8.c > @@ -1151,18 +1151,26 @@ static ssize_t quad8_signal_cable_fault_read(stru= ct counter_device *counter, > struct counter_signal *signal, > void *private, char *buf) > { > - const struct quad8_iio *const priv =3D counter->priv; > + struct quad8_iio *const priv =3D counter->priv; > const size_t channel_id =3D signal->id / 2; > - const bool disabled =3D !(priv->cable_fault_enable & BIT(channel_id)); > + bool disabled; > unsigned int status; > unsigned int fault; > =20 > - if (disabled) > + spin_lock(&priv->lock); > + > + disabled =3D !(priv->cable_fault_enable & BIT(channel_id)); > + > + if (disabled) { > + spin_unlock(&priv->lock); > return -EINVAL; > + } > =20 > /* Logic 0 =3D cable fault */ > status =3D inb(priv->base + QUAD8_DIFF_ENCODER_CABLE_STATUS); > =20 > + spin_unlock(&priv->lock); > + > /* Mask respective channel and invert logic */ > fault =3D !(status & BIT(channel_id)); > =20 > @@ -1194,6 +1202,8 @@ static ssize_t quad8_signal_cable_fault_enable_writ= e( > if (ret) > return ret; > =20 > + spin_lock(&priv->lock); > + > if (enable) > priv->cable_fault_enable |=3D BIT(channel_id); > else > @@ -1204,6 +1214,8 @@ static ssize_t quad8_signal_cable_fault_enable_writ= e( > =20 > outb(cable_fault_enable, priv->base + QUAD8_DIFF_ENCODER_CABLE_STATUS); > =20 > + spin_unlock(&priv->lock); > + > return len; > } > =20 > --=20 > 2.7.4 >=20 --b5gNqxB1S1yM7hjW Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEk5I4PDJ2w1cDf/bghvpINdm7VJIFAl5ruhgACgkQhvpINdm7 VJJUJRAAz57BVCZYZOuh2SqAwKCpbzw/pBsx4nWJzQN/u3b9tSf1Fo+wLu94EN7w HrfElOb2SlKWIwANn/lmH7yvbOu1MELJA1YnEJJts/cW09ZuLgLcaTsZ7HrkiEtv 0Bs2vZiiTswifuay+9bKtrkrIlDzDLHJ9ignnDmRHXq5J6jgFTJhDfZ+rrhmAtLQ 0sctX5qRamMFhIzcTUhPJq/dCqxmnc7Hn2znGNoX1cV5PFZZoO8aLkcShCxdO+z+ WHtY3DS8aZaf3G26NSpHoTGyiSk0vJO41H5MqRvFHuhuF/0dvJPDGZZhyNp1Sqr0 X7/lZYSFpjPHOdRlTKAmmmN6/I44c3Y7vkp0263+IEGLD1SndmQEYoqelaYHAAG+ HFJgh4OZ7z+Dur2p4n2x0N8zqLLuDLw02XHWDCex+wu7CUvTfcfYlSfPyvMWmi83 Ja0lYDCk+kbj2xXBB252ZddQ9Uj7J2lTOPBla02ZrAk2k373dXCSiPabdZ8SpdlN QN2lgB/RnRR8tLukryaOl5F70uPaPafxYGenPFVrljYy/lpqbnn+KTqIWvLT4FiD ku/n0vwnfFOLCHwUIzBygzVpptZpfcKjgSAzdElPWeAUr1wyo9BZHU3T2tdTcpYV dA2C/gpiBJIErJ9T0kVR/4gWMUP3gTMHwBRoICE3kWCQFKycHyU= =H8i4 -----END PGP SIGNATURE----- --b5gNqxB1S1yM7hjW--