From nobody Mon Nov 25 20:30:31 2024 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11A061C9EAF for ; Thu, 24 Oct 2024 11:32:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729769581; cv=none; b=u9K5LE+jorMEHz3MZ59zyr77zwwSMA03Fu3BFYRkoPxMC7rXX86853ex/2LYJU4x+dDO9GZw5QhUcvCaBOscLuM/qZ5wY9sUw5QpkRwlp+D0Pi5fR+FppBcPYb+NVXtZAwnR9QcdrosHzGsNlgQ413mCoqD1lsW/hFFF12E8CCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729769581; c=relaxed/simple; bh=EtR59e/+9h+je4mbWsdv/8tBtr6ipuedGd537vHWyEo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CcZTj0u/J91KJYc+JeXovcM5kUKeL6tO2LUYt4kk5hVLNjHlociuOqg8dW1C+I8D+WaUvfFunUhnuYVdn7Urc9n7W3sGpRYV7hsTapwaczYabmaos9zhqiSvVsTcad184O9JlIZ/XX2fJSJ73FjvLmoevvNYbIOGf6YPwKhtqu8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=PIQRFXyP; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="PIQRFXyP" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4315baec681so8313035e9.2 for ; Thu, 24 Oct 2024 04:32:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729769575; x=1730374375; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=JZ/mirgwgAjZlQMvPm+2FBmAjsoLyei227snBkMmziQ=; b=PIQRFXyPWRXp8mNpc2Rk23+VNS5vUqTK3yJdAHJr1YpQRy6gfetdtY8j1tkXc0UlmU 8LnRr0r+G8/9R69ezYeeelMbwBw9ns9qJXgoN3pzuhOzO7MNvQR2fYSMVrbhyX9NWOMq I8Z5LptX4Fp+jf1hnuK0eJk/7xgOIiZDpdiI64tssm2U86Gt1qn4/Qwgj/XaKH9VihCH O5rLZRDwMeK65KvymsDv6C+mqclMXfwZp7meodSQcRF/8u9pAh+JkDrHIt/a67PnafUs 60am9Yb2lFOL5ubsZu1vG6WJj1jBEgjprhmwPx4gyPskoyNeHFfhSSnUp1HvtEU0Ra8I +kkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729769575; x=1730374375; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JZ/mirgwgAjZlQMvPm+2FBmAjsoLyei227snBkMmziQ=; b=qqOZQDmgnE+NVweo4+8ctni+PW9efc5ErmZ/0Jg2NlssemgXIYLH/3PjnOAxPU9ZIR CfXnIOuxfLNdSutvyW4WZVwAd4dFRvPyqDpoPJlb6uVfD3TTQp3cBy/GAEc18+SAACwi cnZHU16MSjmMbsPPRtOg1fvaNRDCsW56rkcZ4HSaS+glThtnwvBiaDkfzui9nIqC0Uxu Toflc8J4SazDzDrbS1YeYg5vyobmzmso5nK21XBPJGj/NqiImX09/AuQbv07fnRG4NSg Gx3yGMFcPwtRd0A45/aTjsKOJ6PYh6BR640FMdA9MR96zx3JsKAez1UtEPZCIlum4+rW GaOA== X-Forwarded-Encrypted: i=1; AJvYcCUhC8mgY9JCRnlTgD/SHYrK6Uopj+c+5lgbeHSYxNe2PUMYXW5js72/BXUnhAHlQmKZVgAdXHwvlyFBvGs=@vger.kernel.org X-Gm-Message-State: AOJu0YwryFZm8H6BSKUZJ93XYViFWdJpESxBP0BPcajTy/TW4ZtXw+qB wALcbYwwnIWKRIhfnm8T+NZDST7gqngoAOe00dhSEWBeuHY5NQIPyvwd2rBt4sg= X-Google-Smtp-Source: AGHT+IFZeRwqNw1uDsh6gIlNZ1JNVdIwXELyLjzTQeBUZCZZdjd5Qppprx6oSMT7zHC4UJfL+x8U3A== X-Received: by 2002:a05:600c:350b:b0:431:46fe:4cad with SMTP id 5b1f17b1804b1-4318c6e8c1fmr12383515e9.9.1729769575100; Thu, 24 Oct 2024 04:32:55 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:17a2:e679:56a4:a25a]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4318b55f484sm14592705e9.13.2024.10.24.04.32.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 04:32:54 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 24 Oct 2024 13:32:44 +0200 Subject: [PATCH 1/5] gpio: sysfs: use cleanup guards for gpiod_data::mutex Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241024-gpio-notify-sysfs-v1-1-981f2773e785@linaro.org> References: <20241024-gpio-notify-sysfs-v1-0-981f2773e785@linaro.org> In-Reply-To: <20241024-gpio-notify-sysfs-v1-0-981f2773e785@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=3945; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=wbHVTkTm1C0gUmYkzNOsSMYN8WOIj6nu1O2fyjTM1Kw=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnGjBk1alXs/1HXQjNSnjKs1lDzlGar0/GrDJIT a9gq7H7jPSJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxowZAAKCRARpy6gFHHX cs2hEACKFi/0C62knN5BYjVREi89SqnFlqdsJp8T0Cgk7D/3XvulNT2VQEkMOhaFYFHoJdo4pZF JemLjv1Rk5hWGe9RWktQT2Ye5Tokk95g0yjOB09oJSMira3SfQXkIUwvac5NXgss5Jd17MrQvdm l7bSR6tZHho0iEqBNv1yP2kPhnmPgfJ4XJzoWKwkPYo33dN+4+QIcN7MpnsqkDycDRGPKzN3l5d EGcLcL4e1Xm1eaVqxH7kF0MSMwd+9XNaObseTrAEUZSxFhwSQ/flZLrb33mSxh3tMDc15lXX3eA /Im7VTzY/O926NCka1ytp5cg951uve1cMX6D3DR/ijWETQnHUCDMHS/HqmhBgIYcTN01S94sQ6g 0onoNOeU4xa2DZ9ZrjoeLbaE+z6KntxSsUXCiWvd0JoOOD7uixocy2a46VN72XUE3+s1iqMxS6K qHL7FApV1mK79Kt3tLncRwoPUBbDazy9SVUM+bM9jG+qJympC2q9tCDhNTFI4as/8nRVW3S0yvk UjYP9Mxhq2s60IHwIJRvC8n0L1KXp6WK+JMwjmoJj6TnM4HEOxwhaGScJjJ+QG5Zm3uaP+j0An+ V07WY77DDSDSvONAYhde1oZwUxl2F8eAAAmoLsT8hJ0WYCz9NWp0jd04CUm1chsT1r55ZOfG1Pj tkgi61lFZmckrfg== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski Shrink the code and drop some goto labels by using lock guards around gpiod_data::mutex. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-sysfs.c | 57 +++++++++++++---------------------------= ---- 1 file changed, 17 insertions(+), 40 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 0c713baa7784..3ccb41a93ea7 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -77,12 +77,10 @@ static ssize_t direction_show(struct device *dev, struct gpio_desc *desc =3D data->desc; int value; =20 - mutex_lock(&data->mutex); - - gpiod_get_direction(desc); - value =3D !!test_bit(FLAG_IS_OUT, &desc->flags); - - mutex_unlock(&data->mutex); + scoped_guard(mutex, &data->mutex) { + gpiod_get_direction(desc); + value =3D !!test_bit(FLAG_IS_OUT, &desc->flags); + } =20 return sysfs_emit(buf, "%s\n", value ? "out" : "in"); } @@ -94,7 +92,7 @@ static ssize_t direction_store(struct device *dev, struct gpio_desc *desc =3D data->desc; ssize_t status; =20 - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); =20 if (sysfs_streq(buf, "high")) status =3D gpiod_direction_output_raw(desc, 1); @@ -105,8 +103,6 @@ static ssize_t direction_store(struct device *dev, else status =3D -EINVAL; =20 - mutex_unlock(&data->mutex); - return status ? : size; } static DEVICE_ATTR_RW(direction); @@ -118,11 +114,8 @@ static ssize_t value_show(struct device *dev, struct gpio_desc *desc =3D data->desc; ssize_t status; =20 - mutex_lock(&data->mutex); - - status =3D gpiod_get_value_cansleep(desc); - - mutex_unlock(&data->mutex); + scoped_guard(mutex, &data->mutex) + status =3D gpiod_get_value_cansleep(desc); =20 if (status < 0) return status; @@ -140,7 +133,7 @@ static ssize_t value_store(struct device *dev, =20 status =3D kstrtol(buf, 0, &value); =20 - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); =20 if (!test_bit(FLAG_IS_OUT, &desc->flags)) { status =3D -EPERM; @@ -149,8 +142,6 @@ static ssize_t value_store(struct device *dev, status =3D size; } =20 - mutex_unlock(&data->mutex); - return status; } static DEVICE_ATTR_PREALLOC(value, S_IWUSR | S_IRUGO, value_show, value_st= ore); @@ -253,11 +244,8 @@ static ssize_t edge_show(struct device *dev, struct gpiod_data *data =3D dev_get_drvdata(dev); int flags; =20 - mutex_lock(&data->mutex); - - flags =3D data->irq_flags; - - mutex_unlock(&data->mutex); + scoped_guard(mutex, &data->mutex) + flags =3D data->irq_flags; =20 if (flags >=3D ARRAY_SIZE(trigger_names)) return 0; @@ -276,12 +264,10 @@ static ssize_t edge_store(struct device *dev, if (flags < 0) return flags; =20 - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); =20 - if (flags =3D=3D data->irq_flags) { - status =3D size; - goto out_unlock; - } + if (flags =3D=3D data->irq_flags) + return size; =20 if (data->irq_flags) gpio_sysfs_free_irq(dev); @@ -292,9 +278,6 @@ static ssize_t edge_store(struct device *dev, status =3D size; } =20 -out_unlock: - mutex_unlock(&data->mutex); - return status; } static DEVICE_ATTR_RW(edge); @@ -330,11 +313,8 @@ static ssize_t active_low_show(struct device *dev, struct gpio_desc *desc =3D data->desc; int value; =20 - mutex_lock(&data->mutex); - - value =3D !!test_bit(FLAG_ACTIVE_LOW, &desc->flags); - - mutex_unlock(&data->mutex); + scoped_guard(mutex, &data->mutex) + value =3D !!test_bit(FLAG_ACTIVE_LOW, &desc->flags); =20 return sysfs_emit(buf, "%d\n", value); } @@ -350,11 +330,8 @@ static ssize_t active_low_store(struct device *dev, if (status) return status; =20 - mutex_lock(&data->mutex); - - status =3D gpio_sysfs_set_active_low(dev, value); - - mutex_unlock(&data->mutex); + scoped_guard(mutex, &data->mutex) + status =3D gpio_sysfs_set_active_low(dev, value); =20 return status ? : size; } --=20 2.45.2 From nobody Mon Nov 25 20:30:31 2024 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 066FE1C9EDC for ; Thu, 24 Oct 2024 11:32:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729769580; cv=none; b=vCzwGIHvs0KcQbqiQGBm17/WVrezsfZt5MUDid6QakIOQDziiIk81kA/EV2E6x3f3ZfCx1/gO8opgGr8dlqpzEJnZsmb9y2Ln6Voi0ZCnWH1x7uulWBy2W42Kl8MyA2fQNQT5sNlFsgFSIh7wcy1wCgqaA1janmOpub/3javCEM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729769580; c=relaxed/simple; bh=DXgv0hQbEavjEXHUJ7lWXUDCfXNq2OJv1JHzdTSsOv0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SLUMavHGQjHPEgLjzV27Vc9kMN07A1eRS5feReWtCkhEdJi1fQQczlT7OAlUoHQE1cFncwtnOOks2fDVMCDzgplqnHK41dbrXBK05OUMs7jFtMRp3jYqAEpgIfv98+q/7F9EF6N7JH382b24FcFb3SHNId9f7etyV++g2kwBd/M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=EQXZ5blY; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="EQXZ5blY" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4315abed18aso8139825e9.2 for ; Thu, 24 Oct 2024 04:32:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729769576; x=1730374376; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=T2XWx28w3iO+qAX/HKcN5qd2YZOsL+/Ftl84I6U0yX4=; b=EQXZ5blY4DHZU/37juVLrAOYg+o5INJZT5gjr8TuAPUt9VpAFcrbrfEEgsAGBXhNsQ kGS6Jh+FolnCEU0BfLURjvtC0iIzwDnl1v0TZeQQyPEjdxbgj6g31ejlmS71I9VtnrLQ BOSSDSwBlJOFZtOYxmmy5lpZAyRJFD61s3opkjQ76aNBpjWKB3d0d589eYUzhxhJJJDB EJMnMiK66FIZDwhCPzVxuGXVluyWxSL8u/2WMUEPWFoXhXBUbUshdzzcTNPHs6uZ5FnJ 67D+1Hx9/SoI5oWL/6PNR3tGxv0aYybZqjAtl6+m55PuhLYFUUohiSHXsXwLetv/xjWB SCSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729769576; x=1730374376; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T2XWx28w3iO+qAX/HKcN5qd2YZOsL+/Ftl84I6U0yX4=; b=rJdB0Ev2ASE7MNDUyS5tZJzrsuVWoluiBg53LhmqMMoODQY3r5L8dGmFqNuyQME1Ka +4zbTrTYnbUJFX41vKN50ohWFlnKjdY+QRtEvcTXUOEKtZqIS1C/nd/2SEjR3iUU4ZIt 7HY2ZTPED9ru/9V8K7z60CQp4h5N7jcAf++Tt34vLfYre4DKWyalGrv7S0+yRMGwq7Hv 9mQJi4UN2jblG5NQ72ES9yTgOHsIhCVBgJR4/OSCCFT0CCOAnFkRWoUe8k1MI61qGEpr d3alxfGxrE15FWwSNRYTnxQfp2N4WgUwe6JrKgbvyitNjRF+E9MHonBMBJEtRHQX1id+ 4Tmw== X-Forwarded-Encrypted: i=1; AJvYcCVf8Z0fPWh5I7qvS2WofniFmzwtVk3wnpJBVybBya0sXrFk89y0ktZQV8dCu15oDil2Q9+xKVICHE0ylpg=@vger.kernel.org X-Gm-Message-State: AOJu0Ywq+N1OKyjmMexmuPAs5cJkgj+DlR+XDdBi5ZJcwtnExcwJmCIH Au4H6n3YMLHLuBQhPGwvdz2O/NSLd36/Go8bg3p/hUNMc9noN/Pr18bJ6R6ii9o= X-Google-Smtp-Source: AGHT+IG8UaV0m07KAHdYpd2CksFVwm3hIUl/RZ8jsVafhZ1o4Q3OfoXRd9b+pDvCLGdIwRm2jcmEOw== X-Received: by 2002:a05:600c:19c7:b0:431:5ce5:4864 with SMTP id 5b1f17b1804b1-43184254536mr39428095e9.35.1729769576134; Thu, 24 Oct 2024 04:32:56 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:17a2:e679:56a4:a25a]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4318b55f484sm14592705e9.13.2024.10.24.04.32.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 04:32:55 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 24 Oct 2024 13:32:45 +0200 Subject: [PATCH 2/5] gpio: sysfs: use cleanup guards for the sysfs_lock mutex Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241024-gpio-notify-sysfs-v1-2-981f2773e785@linaro.org> References: <20241024-gpio-notify-sysfs-v1-0-981f2773e785@linaro.org> In-Reply-To: <20241024-gpio-notify-sysfs-v1-0-981f2773e785@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=3494; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=BcN9dryIsrJqG1KRF+BFPyvkm3ZgVKVdWwWtFpm+Vcs=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnGjBkeLsVV/6Dj+k2jmzftuCgusZt+SfK9bVxN rPAPbhswlSJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxowZAAKCRARpy6gFHHX cn3/D/90mHQdPWa+5+GniU7DYpq0BE1RF1HohTeJ5HMOO8rVivqfY9faq8LgJMZrcJTfnvTOb0D dQsLCF1W5PvLG5f/bhq3D5W3ITGQPoOA4MD8fjwmtnboASemjXYOTmBuZhGgkCCB7t35rkgslR0 18kH2EgXfs4jHYROYLors4dsmsNFv0iqisRWJDbBemuc1rgI+beBh6uEvOXj/fBA8QQ3eadzh+i 0qfnjXPmflUeFFp2b2PbdUn0i/aYm6UrH7IsxAoJ3uNwgMmGBVOM2L3lx90lwemrz9I092+00kd etBaJ9BhqwSWpNKE3yvvLTNklhVPznKNT/EvcbVTXAqMkwLtVEuYl5HLYApOAlCoFju+OuIjfMr VgZUWv7CJwNt1tuZiBxQfs9q95wrmBMCH08uEmZTKQCTIoWk7lCbN72k33PbUuwB8fPutuHEyIJ qWhXvofkeQVo9UVNlB2YUJLBDj4ohE6Tv0LqwraWCIKBLsQGvbp61iv1jck8AohRt+5GAFMR0zx 08Zsbe3xcoN34xT1ISrRuY7Vqec07BMRIJ+szQfygTEYWzJe2lFZ1CshffduJTc/uPx6BcamF9c o9OJSlk6fSj9REJj4cGjnuETNHHIL8DYgmGO3fFa++6kW8gIjfpQs869afuNf8JyviJ1YsJ9Ai0 ryZcSEG1Wg9r1ag== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski Shrink the code and remove some goto labels by using guards around the sysfs_lock mutex. While at it: use __free(kfree) when allocating sysfs callback data. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-sysfs.c | 64 ++++++++++++++++++----------------------= ---- 1 file changed, 26 insertions(+), 38 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 3ccb41a93ea7..096f79bbfe42 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -550,7 +550,6 @@ static const struct class gpio_class =3D { int gpiod_export(struct gpio_desc *desc, bool direction_may_change) { struct gpio_device *gdev; - struct gpiod_data *data; struct device *dev; int status; =20 @@ -574,24 +573,25 @@ int gpiod_export(struct gpio_desc *desc, bool directi= on_may_change) =20 gdev =3D desc->gdev; =20 - mutex_lock(&sysfs_lock); + guard(mutex)(&sysfs_lock); =20 /* check if chip is being removed */ if (!gdev->mockdev) { status =3D -ENODEV; - goto err_unlock; + goto err_clear_bit; } =20 if (!test_bit(FLAG_REQUESTED, &desc->flags)) { gpiod_dbg(desc, "%s: unavailable (not requested)\n", __func__); status =3D -EPERM; - goto err_unlock; + goto err_clear_bit; } =20 - data =3D kzalloc(sizeof(*data), GFP_KERNEL); + struct gpiod_data *data __free(kfree) =3D kzalloc(sizeof(*data), + GFP_KERNEL); if (!data) { status =3D -ENOMEM; - goto err_unlock; + goto err_clear_bit; } =20 data->desc =3D desc; @@ -606,16 +606,13 @@ int gpiod_export(struct gpio_desc *desc, bool directi= on_may_change) "gpio%u", desc_to_gpio(desc)); if (IS_ERR(dev)) { status =3D PTR_ERR(dev); - goto err_free_data; + goto err_clear_bit; } =20 - mutex_unlock(&sysfs_lock); + data =3D NULL; return 0; =20 -err_free_data: - kfree(data); -err_unlock: - mutex_unlock(&sysfs_lock); +err_clear_bit: clear_bit(FLAG_EXPORT, &desc->flags); gpiod_dbg(desc, "%s: status %d\n", __func__, status); return status; @@ -679,36 +676,28 @@ void gpiod_unexport(struct gpio_desc *desc) return; } =20 - mutex_lock(&sysfs_lock); + scoped_guard(mutex, &sysfs_lock) { + if (!test_bit(FLAG_EXPORT, &desc->flags)) + return; =20 - if (!test_bit(FLAG_EXPORT, &desc->flags)) - goto err_unlock; + dev =3D class_find_device(&gpio_class, NULL, desc, match_export); + if (!dev) + return; =20 - dev =3D class_find_device(&gpio_class, NULL, desc, match_export); - if (!dev) - goto err_unlock; + data =3D dev_get_drvdata(dev); + clear_bit(FLAG_EXPORT, &desc->flags); + device_unregister(dev); =20 - data =3D dev_get_drvdata(dev); - - clear_bit(FLAG_EXPORT, &desc->flags); - - device_unregister(dev); - - /* - * Release irq after deregistration to prevent race with edge_store. - */ - if (data->irq_flags) - gpio_sysfs_free_irq(dev); - - mutex_unlock(&sysfs_lock); + /* + * Release irq after deregistration to prevent race with + * edge_store. + */ + if (data->irq_flags) + gpio_sysfs_free_irq(dev); + } =20 put_device(dev); kfree(data); - - return; - -err_unlock: - mutex_unlock(&sysfs_lock); } EXPORT_SYMBOL_GPL(gpiod_unexport); =20 @@ -749,9 +738,8 @@ int gpiochip_sysfs_register(struct gpio_device *gdev) if (IS_ERR(dev)) return PTR_ERR(dev); =20 - mutex_lock(&sysfs_lock); + guard(mutex)(&sysfs_lock); gdev->mockdev =3D dev; - mutex_unlock(&sysfs_lock); =20 return 0; } --=20 2.45.2 From nobody Mon Nov 25 20:30:31 2024 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E13D41D0B91 for ; Thu, 24 Oct 2024 11:32:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729769582; cv=none; b=gdgqIE13nBcwtQqMj4xblUkbsoaOB3CQlnEVlWIwyND4dNouGXUpV57MFLsSzT8hkVcS5XQfN6jXsfE58i3J07J59g+Qnl8BKKib9vG0wc/NuzwO7gZcEAS3DdE+RHuw53B975XbKS8ySwEBLb1AGtedphF0U0lQw42FeTUDH6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729769582; c=relaxed/simple; bh=U27NwsOlcsHUnyX5fd50gH6i+uOe0vRVGONCZxUCxtg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ey0eM83luVjhR3dUQhLgFL7i6jGIIDBak9rYBGYPMpiI1Rxyv8jToHCryxHxJvyUdRe+tR9QL3RcdXRmlyEZGJwcObx9WZ+mYHqJ7XUekoRx/HdHsJpf23ktYMhwf/r8RO3SsKW4Y5fM7Sq4gtxlvBAYV91/LVQGEbkiqMRT1RE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=3T9wC91G; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="3T9wC91G" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-431481433bdso8098305e9.3 for ; Thu, 24 Oct 2024 04:32:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729769578; x=1730374378; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Yo2F086X03vDK4v4HIxfZTPhSHiiOHsxDuitRvtDxBM=; b=3T9wC91GA3q+chkvYBDN/gxexslb87+UiiaxrCLNFZPHeZ8yHB4RRJGbMpGUsUs2nm wcTUrYH7jSzGfZQgzfpEcs9gHf5cfbXXHPbJIWeUjxrm4tJOvTqnD//KaK3nxCQB19DX FX/Cbh4y2bRARw61in8WryOZOLC5pdUUOpE3aAOSniZUkBVJlDn9zTfBMFOA5z0dCm0s 3Bt0SuKUhc639tnBO1kX3pHGCbOhheWZetnKV94tT4yOYDxnaz4XdoBM3vPIfvAbZlTZ iOMnTgCSvL7r6ydggC0IRBH5bUvA4o6Ggg/cg61xIY1zs5iPaf98tnL035y6kJM9vSDa oVLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729769578; x=1730374378; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Yo2F086X03vDK4v4HIxfZTPhSHiiOHsxDuitRvtDxBM=; b=FCvkBTCXm7syJ2lITnvEFMUHxQruMqpyM3a6VbcndhCprstpBSoj2SA1aJ2hWFoaEt B0cOBGAWxHXTKx8l4vSitb4vSRngOOF/B/WDeBlIe10qtjt6EvuP74Jqw7oKVdFnRGIN 30fGZW5Kuyv8Bwp9alJLoEPqxXJsJkj0/SI8i52mlDo7Lqo3uFswGJvFVStgqAP8TVbF HyiFDHZdH+0te3FzOnB2W9h7x6rh8Q+Caxsy59GudWYg37sUwMWip2iCydlTeOjD86Uw 0vAobmT4e/dAWO7r8ciEs5BIn8XhZQXCCkh8UmF5bDyJRbo23rEKJAF5Y4z2KLWtFWug S/gA== X-Forwarded-Encrypted: i=1; AJvYcCUSl9XW2LaXTBouaruWhvvANmu6Iv0vlg5yvjJiZ0pFAdM6DfUBsJ3C0zlWM2CfjPoOEEimRF0d+HgOe74=@vger.kernel.org X-Gm-Message-State: AOJu0YwlcX1YHgy+XkP7hLQVvuDNxPyLh9KXyMi49eUox3mJNvcT1VzJ LeGBpieiiYZQxtj1jCXmSK+1t9FATwXrqxgExSdzGOO8iRyXzLwGtMSzF35X10k= X-Google-Smtp-Source: AGHT+IE6+QMCz2x9j9j4XF+SLSco9806pGLmjIXM+yZNAW6oDXw6qPS7BlFhrpdWX5vIVxu91aJk0Q== X-Received: by 2002:a05:600c:4fd4:b0:431:7c78:b885 with SMTP id 5b1f17b1804b1-431841341ccmr43071255e9.4.1729769577330; Thu, 24 Oct 2024 04:32:57 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:17a2:e679:56a4:a25a]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4318b55f484sm14592705e9.13.2024.10.24.04.32.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 04:32:56 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 24 Oct 2024 13:32:46 +0200 Subject: [PATCH 3/5] gpio: sysfs: emit chardev line-state events on GPIO export Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241024-gpio-notify-sysfs-v1-3-981f2773e785@linaro.org> References: <20241024-gpio-notify-sysfs-v1-0-981f2773e785@linaro.org> In-Reply-To: <20241024-gpio-notify-sysfs-v1-0-981f2773e785@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1117; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=QdbVjjJq9AljOJ1NVlDiLyI0Sj07rkOhyPjJJMW5vcA=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnGjBl9M8uueSCSt9bwVmONrgpP6XVzockfOTDK hoxzYSvztCJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxowZQAKCRARpy6gFHHX coiFEACuX1TsZETKpTUl3+YqbrG6vReDr1LXksU2PJiX3b/klEX2TJYubIdVfonwL4ksrEri6Lt 3IlSaPHqgTDptIL55/Gibq+2zxia6gynsZ9jq9aqVemMRjLmAUtXGuQBRJ6TzyYXxbWSpy1Zbn1 nsPcWViQv3Ff2eim+bPZVUbD6avJUAotddx4SyfNRWYSppr8KrB6xv+C9b8JOh+BnFgof9pggSb 3SBxumhwircKYx3ZLV4I6OGlhwS0AO+ZW2JX5lQcvv+0jX32XbPush1FNR6Wb9Gbdz+nYeni7sB 0ZyPRlsN8ob58BuUxEGDhjFjRF4GT5Nt0bTQ7zWMdtQOUfyw0k1CieglOiKQmm0xqmXBzne96WN ewVWhtIBHtUaTnukNApcVuFCeEC2AEgXPuK2v2Fd9TBt36n1B9+NjtmVkaMa3iZyzNlDewxhOIX M+vpHs6SPzKOrti44wH5LTh0xSEFkoCB2zqPXc33LaG2M/h8KyFj8oC1LslLMneQN/UZC0Wn06H 6FtB9b8A9GRGa1Pz4yjVunCgVznsFP/2RSBi5qaUhQR96ClFL9bkk+cSnrsr5JJ16Gz7Gp5GqHt YRDwCAVTLcLxHgGFnUXqc9D6i5li4C0rcuegO2HfdOgdR19HSxmv0lrZdEq+/8t+J7tRNFkifyn kfjff5kPZqGWq6Q== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski We already emit a CONFIG_RELEASED event when a line is unexported over sysfs (this is handled by gpiod_free()) but we don't do the opposite when it's exported. This adds the missing call to gpiod_line_state_notify(). Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-sysfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 096f79bbfe42..3f24bf278b77 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -21,6 +21,8 @@ #include #include =20 +#include + #include "gpiolib.h" #include "gpiolib-sysfs.h" =20 @@ -470,10 +472,12 @@ static ssize_t export_store(const struct class *class, } =20 status =3D gpiod_export(desc, true); - if (status < 0) + if (status < 0) { gpiod_free(desc); - else + } else { set_bit(FLAG_SYSFS, &desc->flags); + gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_REQUESTED); + } =20 done: if (status) --=20 2.45.2 From nobody Mon Nov 25 20:30:31 2024 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C24C61D0942 for ; Thu, 24 Oct 2024 11:32:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729769583; cv=none; b=IwrD4QrW5WaXfR4H7gBoJfzZ07D/waBTM7Z3kvl9s/X12ioThgAiivVPekOVhclyUWGhCgQ6UDtXt4cvjFs0OTkBD5vHHSgO35Ee0SneWf31NBXFKdICxlnHUkZ6dGlz1gTpG9iNMvYF776rAIhhEKYKH3d+3IZD97MqcEddTs0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729769583; c=relaxed/simple; bh=Pgjbt4XEQg7IVvK0FnWvm567PSzKpKRl5JNn8e/2W1U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sGzVxz3zR+4KaEVsy7Da75x/Ak8z5ASF/WxAB4PLc4T93xP1TDGuIHnZS9zjhkRO1o29cB/nzq0SV4XU9tnsmuIxjT3RKkbG23P7Gc6JQRcYKrH9Q0lUl9cyaXJ/eBDE0dqe5BtDHBZa/P+CcAZO4545mqd66Xcqjuptik02Jo8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=ECmI8sZM; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="ECmI8sZM" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4315eac969aso5342575e9.1 for ; Thu, 24 Oct 2024 04:32:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729769578; x=1730374378; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=eppHTEc5juuyQhtpfQNDsJTRqz3tSRocJdtDsSnuBKU=; b=ECmI8sZM630DdPugC9s73Uq4toUSefGrB54Py84HMULLoBNlneoJXEjaK7EHl/61KZ 0XrUjlYdtelgBEY8m3O/YvrS/oGOMBqgQDWsT6yjCA2FU5MY5eP3SOqnMrfOIB8zWgM5 7JCPnGgGU9epz4SB2AREJULgZUcVVnlUSvO1eQ86otURnW+i1y32RHSRwkLNQvCT/B8S 4kjfwMyjkwCHAl7QMH1eCyPzeRtjW7YyK4JgQgaCts2UOYBrwjhMqjqsEx/PZ8jqqL3F jfWSddxdy8emzTrhUWhnRx9Auny8bpptLBmR5Rv0dAMFi8+raMcw/1wJ0G8Gl4482O0J RtcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729769578; x=1730374378; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eppHTEc5juuyQhtpfQNDsJTRqz3tSRocJdtDsSnuBKU=; b=nQ2qLdgvoFSs+c/ZSPe/D48ksW9w8XznyMyhEY8YgYuxh5y7oAJc4+A21DIiZ5mlJk wRVnWIb34nTjWTuQJZEeW6lmyiSdyHNA/GmanqaL+zcDKwdTNwBxQpGcZEqyMyWYPP1A ar8YVpgmUbsARykmUsFpu+u2LOX6k1xWTFH64ZtGsKxAV5l+po+fLpl3xSRlyWPONqx6 U+7K1LNk00unJ6H5T34G2Yzl89FDDcmt2NhxikxHUEb6dByznS5QRBUZV5InVVilM5HW 5SEBEMr0XMAYdqEIfB+jVtedVwK3UCLPsqXM0NCKxcKzC4XkEGb9JnapXq1Fr1V69YNh nYpQ== X-Forwarded-Encrypted: i=1; AJvYcCXJl83qpZZNtMeOYA6eQKZxWYWf900prMeT36rgII9ARNvXm3ODshePAGZ6Ba93T4dTGQHqPaxyMtkyyQc=@vger.kernel.org X-Gm-Message-State: AOJu0YxUoVJHWMIdWUaO34mhsPVtQpkJ5eeIUV+uQbcZOH+SElrPv8Po tALAQ74JQ9ZhlfF1ftNVTL4yYKxXOU3TJlkHkmIdU3EsQiKr41fc7DpWE0yffwc= X-Google-Smtp-Source: AGHT+IFAqZOlDHc20yl4zCduffrqTXZO5TEJq9dnErjWksgz18FfOD/vpC5qpY6ZCJZqLnaDJ5ChqQ== X-Received: by 2002:a05:600c:3d95:b0:431:4fbd:f571 with SMTP id 5b1f17b1804b1-4318bc8e1aemr10970115e9.13.1729769577994; Thu, 24 Oct 2024 04:32:57 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:17a2:e679:56a4:a25a]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4318b55f484sm14592705e9.13.2024.10.24.04.32.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 04:32:57 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 24 Oct 2024 13:32:47 +0200 Subject: [PATCH 4/5] gpio: sysfs: emit chardev line-state events on active-low changes Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241024-gpio-notify-sysfs-v1-4-981f2773e785@linaro.org> References: <20241024-gpio-notify-sysfs-v1-0-981f2773e785@linaro.org> In-Reply-To: <20241024-gpio-notify-sysfs-v1-0-981f2773e785@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=781; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=XnelKBDV2L3pjwhf9M2fvoOno9GcTcQCBzk36loA66E=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnGjBlyWyQzGnbxAarpCwmXTQ62BDPLfW2FkmRd 1sEt7+T3ryJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxowZQAKCRARpy6gFHHX cgW2D/946L+i6FaZgycLVtPIWSfoY21UtUpvxZt9JAC3byWmPIQ2BZrUcnTAun7sJFvVRDVPsy5 7zGpkJXvMBSJftbE8Iaoz4aLadyVoD+aDPsbeT6Hqlfly7t1Fb+w1Jxye3dDbw496Uajz4uR5v0 jXEJDeQRqaX+zjm1+BqoKgUh+COKFo5GKGfmKGIVO07gGkQyIQi/IjntiTPB6LNbaSzVK240yQY YNjNA1kszgmzc1OMX33hNztkMPhXZ+MuGGdeNFYrf9X09hy73iC/gtyQ3mBIsNY3TqKKDBAfDRe jXS5l/r4aD6VdUUeHL4jJgi6pU8ZInK63OErro8unnGI0VXBaNVXvoMzIxrwnYAA1cXHZAnJ/Al Xc0UXw8/ZaiA0HljspmQf9/B1XdiP0tENtBYK3xfh4PHolG8k77/Yt7A/divJwga2vXfLyFC93G M5dRMt6ROZvVt1uoK/oZMbPAwJH/2OzqYmnIkPwluLbDzcg9iFGgtnIB7Om++q/9XMpkSP04oty t+KZa0P0dTLvgoLIfoSYpeaPOlnTSmKYGPUbwHnQcIXp1ESFZ2urW7f35qJG1TRiZq7R9gXxqR0 X7ecYb4i+pjN/Sm0jG/clsbhh9bDZZQlXeswBF+wv1qad5ICn3RIRzTP0Z3fmiSGRcZxTPJkids J2DGBrpG5SuDrUw== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski The sysfs active_low attribute doesn't go through the usual paths so it doesn't emit the line-state event. Add the missing call to gpiod_line_state_notify() to gpio_sysfs_set_active_low(). Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-sysfs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 3f24bf278b77..b967b76ea046 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -305,6 +305,8 @@ static int gpio_sysfs_set_active_low(struct device *dev= , int value) status =3D gpio_sysfs_request_irq(dev, flags); } =20 + gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG); + return status; } =20 --=20 2.45.2 From nobody Mon Nov 25 20:30:31 2024 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4B2F1D5174 for ; Thu, 24 Oct 2024 11:33:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729769584; cv=none; b=hxBGLGOt4uLcLe7u4HPvwQDPuIwG/2DNfoTUIu+UY1cyl5fIOkPeQpnGwqnITB2gX3XjPaeXJ95B/CB+bXZtzFAyajDYy0UtLmSX/juORffuzS36PiS5Q4z+Pz0X2Cs5lRZ3iIxCUkOITzprcp4Z8oe1LKePrVFlYypn8KFwjRo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729769584; c=relaxed/simple; bh=AcP3LRuJVhQQb1vFB0v3JqR/A+j4tQ4v91oKntLbohs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=M9/SlJye+4hBQPWQiJKZeKs1iKqxy4gnjWNKAb9Ibm6/ZtgpMQwMFS0aCvH/YVaEoBj5uKi5fYwAUO7WVR/8PmzJmaO75Z7+7c+88hHPbRMoofyXHPHdBO7+GYcIwFFSKNrdZCjLL8iuECJ0PjDh+5Otat8kDqqSw9Hwosw20/8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=vkyZrL8H; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="vkyZrL8H" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-431616c23b5so5788685e9.0 for ; Thu, 24 Oct 2024 04:33:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729769580; x=1730374380; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=cVUCjb6yUFKCfRWoeiG90YmWbQXs1nb8uTKus5VOhlE=; b=vkyZrL8HkQ65y+rOY/Ni+9CQD/iBYI3QAfzN3J+souFgYq51zor5Dt2RN32YtMLCx8 4kcwGYZ7BBispm+Nne6bpuLspMvVbxdbe79XVUaHIg63l555HVhNuBktCeIt+GJPVZmB zBk34PRV5Xc7dPmCiU2Zf/AsmeFpWKF2THfHGOzu8WtiIdOqtnWpQVVaVMn/xMovmIxP c9kYb/qaP1E0a8a/nkZ2SfbWPvwAiYRNeEz/CzGduaWJSaMDI8BV5WtnydGLvBDNG4fI uIQkpAoUsJA6p2U7OWoAVUjZ3kiRmaNRi5TDaJUad7kuY0TUVhgnKFVmvtmlgOOH+Icd uV/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729769580; x=1730374380; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cVUCjb6yUFKCfRWoeiG90YmWbQXs1nb8uTKus5VOhlE=; b=VRkhFQ1GNU+Fta8SryYIL9/jfNhGkYx4N+qgOX2D4B2Git2Or6c8Hv8U+GRiSnV6Gg BwKCTKkH79nFyfqEP+ZFxknF9kgkfMzr6NZQivm78v+Arkao/8a721TcHLZli3LkFXPY eRRkB68wB942G3kOskp3QFiD4EpVJrFhhjCaeeIlIrfTdRATXiDPeYsC5V5iXiedpn4w khpTQxj8YZfn2PHEcibshW3Qa+IJKHgi4XP/WBKkSYi+YB1NXGb+Gb9+TttaK1XrzdzN thHxG1u/QoHVR3qVUo1MNYy5MnY8jddDXOnZZIR3aCM24cdCzYHAYXE0BSBMMktZqCSX WK/w== X-Forwarded-Encrypted: i=1; AJvYcCXGngAoGHYfkZzwAhXjVpUUwCniHtj+3fU7A/YicfVjOLT8ZG2kIICvk7hiM5lumoV7FEAefQOAiv+l2g4=@vger.kernel.org X-Gm-Message-State: AOJu0YxhJElekBlRwDngT0fYq3xW2uYBIIwXaD+asRX/2s8t6GDDjzA3 LkhpAeOJXw2AK4MJ4wnZovinAsp9iFtWtn1SQ4P8RfhpcksXOHnyvy+SL9J64J0= X-Google-Smtp-Source: AGHT+IGSFvBKFRVFvktWFj6u484K80hk9Bkb8d80U6lHG/wU1Z+nh1AwX5AZM6vnAwkGa8gBq5QYhg== X-Received: by 2002:a05:600c:4689:b0:42c:b826:a26c with SMTP id 5b1f17b1804b1-4318b5a561cmr11467275e9.8.1729769579999; Thu, 24 Oct 2024 04:32:59 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:17a2:e679:56a4:a25a]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4318b55f484sm14592705e9.13.2024.10.24.04.32.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 04:32:58 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 24 Oct 2024 13:32:48 +0200 Subject: [PATCH 5/5] gpio: sysfs: emit chardev line-state events on edge store Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241024-gpio-notify-sysfs-v1-5-981f2773e785@linaro.org> References: <20241024-gpio-notify-sysfs-v1-0-981f2773e785@linaro.org> In-Reply-To: <20241024-gpio-notify-sysfs-v1-0-981f2773e785@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2136; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=IMu9CPsbEhOzI49XGiXeQAFdqhkYj9ry4r52yggQ+4c=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnGjBlLHjX2h0Wt6sRGmUPUdxKOZh7OEMvVxdYL Xp29YZBS2+JAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxowZQAKCRARpy6gFHHX coivD/94qe+Tm5SWXorKelZfrrNlk2Uj6NapVog03yPeDXzF1UewbJKqwVyrI9OEC+4i3tM0eDf 1rQo9iuhfTq7itJuzOVKFwPh9xn/+a4xrEZDDY+0hrDWJb/ESqJFE3D5i0sA+GprxR/5juR45uo rs2sRf8SST63KLOF8REItZrZORCkTwXl/Xc3CqE6wcRaNsg4ROFw8+7qx/x5cQ1qVF4B50yPme6 VuRN1+rFuOobMOB5AQBDIRHuYbpIsMmMUpgTfaLrYsPq7xWJVzcsyn09l4Nw3K3kUPkx01WkMSv cCYdCeIAo0+ngVYlFsbYd28aDG+2VPiHKAyctkbKThmLXcCNml3tyamBbqynxul7HhctamWnyMz Z5213noBOjMOLS7Ce7X1FJaC4BYSRzKpNgB0p9lzx8xsedlRqNEr32m8mXIPeg2QDpXWGHVQnbH 5SnkyCPukEi0v0LgmJj48FrUhvR/E7jSWuq1Y0FXf3Bm93pVlkV3nnHCATg9dTmz2d8Hb8soH0x igS30XEYuI9lJmb9KZRqHT/AqfBB9OseGgVYZJScAAEG3cMy7GdZ/nS/qVsRMISqwu/qVBBPcZI G9cmvoHcWDvyaVUYTPcfVJeTyXYTVcbqsTyKOl2kCABudaYUCegbrwHrg+wEKjk7OIXbeDmME24 T4eoJReqzpGrjSQ== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski In order to emit line-state events on edge changes in sysfs, update the EDGE flags in the descriptor in gpio_sysfs_request_irq() and emit the event on a successful store. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-sysfs.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index b967b76ea046..87f27a0288f9 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -178,12 +178,16 @@ static int gpio_sysfs_request_irq(struct device *dev,= unsigned char flags) return -ENODEV; =20 irq_flags =3D IRQF_SHARED; - if (flags & GPIO_IRQF_TRIGGER_FALLING) + if (flags & GPIO_IRQF_TRIGGER_FALLING) { irq_flags |=3D test_bit(FLAG_ACTIVE_LOW, &desc->flags) ? IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING; - if (flags & GPIO_IRQF_TRIGGER_RISING) + set_bit(FLAG_EDGE_FALLING, &desc->flags); + } + if (flags & GPIO_IRQF_TRIGGER_RISING) { irq_flags |=3D test_bit(FLAG_ACTIVE_LOW, &desc->flags) ? IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING; + set_bit(FLAG_EDGE_RISING, &desc->flags); + } =20 /* * FIXME: This should be done in the irq_request_resources callback @@ -209,6 +213,8 @@ static int gpio_sysfs_request_irq(struct device *dev, u= nsigned char flags) err_unlock: gpiochip_unlock_as_irq(guard.gc, gpio_chip_hwgpio(desc)); err_put_kn: + clear_bit(FLAG_EDGE_RISING, &desc->flags); + clear_bit(FLAG_EDGE_FALLING, &desc->flags); sysfs_put(data->value_kn); =20 return ret; @@ -230,6 +236,8 @@ static void gpio_sysfs_free_irq(struct device *dev) data->irq_flags =3D 0; free_irq(data->irq, data); gpiochip_unlock_as_irq(guard.gc, gpio_chip_hwgpio(desc)); + clear_bit(FLAG_EDGE_RISING, &desc->flags); + clear_bit(FLAG_EDGE_FALLING, &desc->flags); sysfs_put(data->value_kn); } =20 @@ -280,6 +288,8 @@ static ssize_t edge_store(struct device *dev, status =3D size; } =20 + gpiod_line_state_notify(data->desc, GPIO_V2_LINE_CHANGED_CONFIG); + return status; } static DEVICE_ATTR_RW(edge); --=20 2.45.2