From nobody Sun Nov 24 22:45:45 2024 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.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 01F9619ABB4 for ; Thu, 31 Oct 2024 20:02:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730404926; cv=none; b=FuZHq+/OVuctYEjy2sttrxbQdcNMzF/KNDxuChV9fFl1ZHRa7j2dZ3shSwPM3Liq5uibuID6S1XDZ/cldbfCq2yboFdcOhIt16y2Qy5KYYWIwiCni9Wtf7FgYM6gai1woghu/zG243T13F5hXWIU+dA1NiIcaJJ3OB0jv3xS2YY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730404926; c=relaxed/simple; bh=3eGsWj3tldB6ErshJTowvNjw6P+DOV6RwonJQjhOJvE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dai0cVM3Bl/vUQ9JX0Jzu9/VoxcXXCPFk4uy0D5G59j9aCvgPIuI8miu2KJGLdiTJedUbjQZ6nLpf71e4jUpMHk5Gtdj/bGUzbrOTnBrBtcfRobyt2g4ovboh/AUfMuAjwyNOJvJkqYa94MnB16SOB+YFUWwEFnmutEuqiJG7EU= 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=csgL3F1F; arc=none smtp.client-ip=209.85.221.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="csgL3F1F" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-37d47eff9acso867666f8f.3 for ; Thu, 31 Oct 2024 13:02:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1730404922; x=1731009722; 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=Y6mBZytrDKEzQaEmUgMpFJx27tSq4OYxz5Qwnw3leeA=; b=csgL3F1FFyjMSD/rfYDkQ0WNDyVi7kAkxOYqo6eTVx6+7PQT1oTjzsokHQcB4iEeX4 Zo57jVqbBHGUDvqXKmkhcWXPiMdt536cKXUkiTOeXC1crR7kKTt/6dfX1ie3WzWm3vS+ /YERwsx05YWnsQsr0JqBa4SWariRFsDioOdRID2C3nOlfyoPiwux1ec5BDnAOR4kR1ra dRSmyLXjAYBGuwORnMmSXuRJPb6CqxaRXO8oUZLcZ1aNHe6uLqBiNvr1mTFl6cgMM1Eh AI0TRFIK25iVtYrEixqR3WHms84CW/G/pjq4tCazBosR518A1lSIuYMbg5zbic7+qCuB 1M6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730404922; x=1731009722; 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=Y6mBZytrDKEzQaEmUgMpFJx27tSq4OYxz5Qwnw3leeA=; b=X6fTdy2TdSikTMAg7GAmmk/WeE6hGgjTX6LB59sTGHPytpYUYQrqW4TIBktn1Sr6FL 9EMRohOJQAPSkpUSiQwTLoL1/9Ua3wpbCjQ61BMcOgOmTE/qAdXqNMI8hxVMOmYRJrKp wg4EKDSYaepevow0IDEEqUG/ukX/3RSG3pD6mzn8Fs8W2xdd21AKu3IXmPscPPXhhVJg WpjuF6Ls75bUUF6lRSHo+hUKmlAIGROIFjMVv4LFczoGx3c3ir/J+X2tCfbWG+nBwK10 TFrS2EBN+T0k4yRz7g4khqTtizuJR3ZMfhkOVnYZeUsji910Yhqd0fTm5bUMVrx0VZIE 11Kg== X-Forwarded-Encrypted: i=1; AJvYcCVYftAeFTyBKq6xYKvKHAPIpi0cR9oaBF6WFc9bwrYImnTRDOxusttqPlnNf36462z73mYRv/TIDiHBq1g=@vger.kernel.org X-Gm-Message-State: AOJu0YzVlJHaRfgkpaaVl+Pt+nT4etBTiKrr410+tJhSISHqhESzIrBZ NLvHU8ykPUe2vZJKTIiRevoxFdWYiZpuOmr2PUsm4ENm+y4LxUjw+YgBwRqPMsI= X-Google-Smtp-Source: AGHT+IGAZj09jlUVqaVWH2c9zCPhNV/xPpwAFq1+xmwxeDkiFGYkJBU61+Cwv42I1Tc9EE4zbt3vqA== X-Received: by 2002:a5d:6c63:0:b0:37d:3973:cb8d with SMTP id ffacd0b85a97d-381c7a5e9d5mr977708f8f.24.1730404922353; Thu, 31 Oct 2024 13:02:02 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:f39e:5519:d578:740]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c1189123sm3003993f8f.115.2024.10.31.13.02.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 13:02:01 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 31 Oct 2024 21:01:51 +0100 Subject: [PATCH v4 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: <20241031-gpio-notify-sysfs-v4-1-142021c2195c@linaro.org> References: <20241031-gpio-notify-sysfs-v4-0-142021c2195c@linaro.org> In-Reply-To: <20241031-gpio-notify-sysfs-v4-0-142021c2195c@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=4303; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=JtNYy2XqnFeY+eoUoR6vsJSZlTSzQbTj5jXZS6NTCW8=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnI+I2Pd20JG6ct2Q64CVWKREET3/J/otoQpcx9 i8hzT2hHImJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZyPiNgAKCRARpy6gFHHX cvnQEADGPCnvjn8sKxmXZbnLjy/kg3253RNE4qwGiWrwgF4giPL4rsiGz8l9e5dTq9J8ZEoREp9 r9XjOoVC6ZCx3Zc5mmnYLahVVYle8h2hDTtiy482PuU/nBDAxkDB96ihhAfaQiBtQEFUuc9No7k PJy5kVfs+n6x99lxIxpKEvXBwD3UX4rAF88N77rEOCOcK+OqDrLtlZT7FV1HDtHpswH9B0f8lhJ rUHGDCVXtGd9dWWcJeSw6EWDQtafbIAzeF33B4OCGzz6RKd822/uRaxaEjHKGMtbztQKpsjZreF QD3pUX5+cKoJFBgdBUPyGVwVnEdjQsGRk52FYSuzugcmSeCCbyi+S0Q8ILYxWR3R0DFOFrBEUsY BrSsqUhdQ8EmIz3MnO8gv4bpaOfanbHR+8HeLlNQB641fKgjh4GI2laBJbupSbOVmeMgwkaLbZg OM3/t+zVJVmKS3h58SqukHCpAIIMuYQgSdFV6bQVakJH4gsuHL9oWOn8550uEB2dxWqjqnYx392 1UPHGZP/VUYUrIfbvmV0eHAQ5ffThHf2iVE/ZZTVLSD3O7u4KZqDf7JuzuZ2n271hUr3xNj99Sr BE4YgiHF50xyzlc+mTHDYQPgwxTRl9AQBFn4ZRU55riHsVYoIu+ik0OMhhl2ZWPVL5Mw6HIA9lE QXhFjVEMn6Cz5KA== 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 Reviewed-by: Kent Gibson --- drivers/gpio/gpiolib-sysfs.c | 82 ++++++++++++++++------------------------= ---- 1 file changed, 30 insertions(+), 52 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 0c713baa7784..a0926a1061ae 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,18 +133,17 @@ 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; - } else if (status =3D=3D 0) { - gpiod_set_value_cansleep(desc, value); - status =3D size; - } + if (!test_bit(FLAG_IS_OUT, &desc->flags)) + return -EPERM; =20 - mutex_unlock(&data->mutex); + if (status) + return status; =20 - return status; + gpiod_set_value_cansleep(desc, value); + + return size; } static DEVICE_ATTR_PREALLOC(value, S_IWUSR | S_IRUGO, value_show, value_st= ore); =20 @@ -253,11 +245,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,26 +265,22 @@ 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); =20 - if (flags) { - status =3D gpio_sysfs_request_irq(dev, flags); - if (!status) - status =3D size; - } + if (!flags) + return size; =20 -out_unlock: - mutex_unlock(&data->mutex); + status =3D gpio_sysfs_request_irq(dev, flags); + if (status) + return status; =20 - return status; + return size; } static DEVICE_ATTR_RW(edge); =20 @@ -330,11 +315,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,13 +332,9 @@ static ssize_t active_low_store(struct device *dev, if (status) return status; =20 - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); =20 - status =3D gpio_sysfs_set_active_low(dev, value); - - mutex_unlock(&data->mutex); - - return status ? : size; + return gpio_sysfs_set_active_low(dev, value) ?: size; } static DEVICE_ATTR_RW(active_low); =20 --=20 2.45.2 From nobody Sun Nov 24 22:45:45 2024 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 583531CB33B for ; Thu, 31 Oct 2024 20:02:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730404927; cv=none; b=ctjnv0920y+Qqq5M7QqKXCnFH9U2BDBE0mYQuTSg1c6Y9njL1lYHltGtKOPbP2+/aBGQOkRg2xAQD1oVRhuBXyY5hbnFHFglhxMKgJ4GTm86rGvQSmbAy5F40wmbKYD4q22QnNcopG2D8kRNQIYaL60yCEHHC622HNOO+hxNIi0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730404927; c=relaxed/simple; bh=lxfcHFlINBm4B273RJGWT9N7EfQtgO45pd+YAFioyAU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=chD+gVKStXQB2m1WncjdOFLPIoTZ0yG3B8cB1JqBQdFI/160wr+bfKwHpqUKdAEcu8uu6/h7j1ZQ70SnwyrEkiv72V7PgKUQUEh805HLz+v0z03uV/uhgT3G19ynLz5g0SRTHKFfa2xi3Ct+koN7FKOuvvjrfG3Ly/U1VRU9oQY= 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=A1vdRIA/; arc=none smtp.client-ip=209.85.128.52 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="A1vdRIA/" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-43167ff0f91so11800945e9.1 for ; Thu, 31 Oct 2024 13:02:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1730404923; x=1731009723; 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=yzrxfr7wPhfTvrfVJLIuoZ9JjJdY5AB7ATojPjTFoR4=; b=A1vdRIA/j6CFHA585KI3akgUqOsi94+PdSdv9J0zO10hiDR2DX0XI4dljLleAgg9Nr X4PGJwG+YZk2aht6+NFEjLFE0poCcIkv2ApIejkVUUwP8P8cp1xyK5viAF7OUHIP0LBm JGayKPkwKHeyy666jM9WwzAOOXO3p7xK/dXk8f/MMTTqV9g43H9tJjnc+TRF9wd2l3+b IuVDgmtM960x98VBn45t3Obg7eFZ0tRACBoYvS1ePGDZvhc3ZkwPCxF8uKbro1EZC7G3 aQPawEFtEqPHUBksukHt5KpbN2QwJHgC6Z8TCHlF5dVduZADBToPmTq5RD9sbrzIt6WM u1NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730404923; x=1731009723; 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=yzrxfr7wPhfTvrfVJLIuoZ9JjJdY5AB7ATojPjTFoR4=; b=iPgxiwkWCXtVKnj0dQ/be6oGIS5QY8GXUuI+FJPE+T5iOLywRXpRiKkD0fHJrwqc5D QtxkDmTj2TajA4xzXr+mjSPzHau6UOCMZd9IZkAxLw9ZBoQmIwiZQQ1nkxuU5E4xUDWY UMHws5cy6wQfR78dB5FZ+IxPkNiWXYBoC4ePV7WgaGQMh1dU1Y6ro5qsBMgSmp/FiMgt X4yjjiGofnvH7Mdv7PfGYYefIp0uScukVoTCSUpS6d/bOB5kvUV7xfOi40tXMfoMi/d0 iTg07Gm+3ku4wxhtzuxnXDgQ773oj73bX/kwMoUMcNzDFDlbpMzkHL5KXtnzx/ctJELt zb5A== X-Forwarded-Encrypted: i=1; AJvYcCWN6RLE21CZG8unNA7G5z/k9IQH75LkT8ZQKsHSEcVsVp1P2RezP3FlZSO7TykcPr7e3A6bThyMzh3/zPU=@vger.kernel.org X-Gm-Message-State: AOJu0YxJmj0T4OBRAjwAwGm1tg93mxSWCKDNYmjvfEROcBvruWpcUe1T xJJMOm7zkDUd/WPuDxsAhq0kWP0cgZUeIELULfnZoU4FcIhSRtWzv/M9r5hkb4w= X-Google-Smtp-Source: AGHT+IGgFm4zjZjWhXC7650nVqWNS1PFsWNFmkOgJQXkZXvXD+FgAP7Ug+L614sjMLXKokJuGBunpw== X-Received: by 2002:a5d:5988:0:b0:37d:30e7:3865 with SMTP id ffacd0b85a97d-381be7d63e0mr3768793f8f.34.1730404923552; Thu, 31 Oct 2024 13:02:03 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:f39e:5519:d578:740]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c1189123sm3003993f8f.115.2024.10.31.13.02.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 13:02:02 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 31 Oct 2024 21:01:52 +0100 Subject: [PATCH v4 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: <20241031-gpio-notify-sysfs-v4-2-142021c2195c@linaro.org> References: <20241031-gpio-notify-sysfs-v4-0-142021c2195c@linaro.org> In-Reply-To: <20241031-gpio-notify-sysfs-v4-0-142021c2195c@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=2976; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=hQbFwd1QT9qA/6G04ep+yw6mU1491E7zvhbWfpDUDoM=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnI+I2RfXIbXJmBgVj3RdDRuu1VHrPbMrDmhip1 i4/Nv5KCieJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZyPiNgAKCRARpy6gFHHX cuR0EADJxy3vXb63V7EH/zHNUnjvJN4b/Jnp/CIAd6WwUskF72NdGGNHTRQzMXEMvcgewrEk2hR 14WOrVchK+ryfS85FkruV8qf94ButgWv0rjh7tf8DvkI+kqQD69+tC70yTCZ4pHOte0Z5zEc2JB PNXUjSFL9RhoeBXWPE4ZsprN5UmtRx9XrNjCCKolq1PrDaGeBnZYrF9DYcGf00hrpTwufg1CbRH mSJ5PnXmCOzGbVVP5J/4dZ4M8RgXYDHr67ZRUAkwRWvginLBwNA5ZZCDKl+LRWbXeSxdhO9uK4C F3Vgeu2H1LBBD96tIzyGVu+rwFlnl+rYBk1Z4xIph6tyfa5vgFfaoMaxBLfKcrZVKj+OHdOZpvl /znYWNXA26/7FinsE5rwGOfKlgJ4NFYrtzsds98qre84LJUw8ZDKwDdaayU7jPP+9siATW0hu4Q jPBJuanaliUmNcxiJNeBvpxqHn2VEs3z+44kvOx/qYZoHg/os6TWE7Un1hKvQorNldyIqZqhHpK 0uW6Q8yuREGLdr4ez609UwHl8Z9XY2BK6oafvDoN1aay7an4wYP1ex8WBvHoy9zge+nlppY8E9G ZA/J09WyVgumZ5XgKYXsyczyHTyAbOePwFViM0D0iEHNWmRQieoyiOAV843wD3yLDfyVnN5cvQZ fK96CAgt4iPXWDQ== 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. Signed-off-by: Bartosz Golaszewski Reviewed-by: Kent Gibson --- drivers/gpio/gpiolib-sysfs.c | 55 ++++++++++++++++++----------------------= ---- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index a0926a1061ae..e6c1e26f302d 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -575,24 +575,24 @@ 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); if (!data) { status =3D -ENOMEM; - goto err_unlock; + goto err_clear_bit; } =20 data->desc =3D desc; @@ -610,13 +610,11 @@ int gpiod_export(struct gpio_desc *desc, bool directi= on_may_change) goto err_free_data; } =20 - mutex_unlock(&sysfs_lock); 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; @@ -680,36 +678,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 @@ -750,9 +740,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 Sun Nov 24 22:45:45 2024 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 B51281CC142 for ; Thu, 31 Oct 2024 20:02:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730404928; cv=none; b=jlJKyQMrGOJyzwrMVoEu+IE/EAMFSG9Dh/fuXTHI/9fSHo2kTC7nvvOs/s+4Ldu0kh1iKJgwAlnumM7refqTK4ZZviFQSw8TqJUzNOppDUsLnrU24xxnXKJUEF1dfXIofjLVIc4dBaRk79I480APV0oAstLn0r+jOpDDdxDDRJM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730404928; c=relaxed/simple; bh=32n8hNRrxZfRWXJHlXEUvVQAOaKpzejZ0VhlHU1F83o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pBs5l7V9lzYlLnpl7rWwsk/WXoMLMi5aWL68w56WBvoANoE7bIuOBDi7tp7Mj09dpo4q5Uf6XCfPzy1MhprtLDSNxN2bvyh1KIZt3A+lPhIiXUh77wSWWywmnD1dDrzWu6NIBLGFvNIzGlGN46lxyZ5YYyQzT2BkbYWwqaD2scM= 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=XPNgh9c7; arc=none smtp.client-ip=209.85.128.44 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="XPNgh9c7" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4315e9e9642so11723445e9.0 for ; Thu, 31 Oct 2024 13:02:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1730404925; x=1731009725; 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=1gPEduXI+XMe6Dm5bWiV+D66hZVETOkYyz3aI9yIIqU=; b=XPNgh9c7MtaX1g3kZDeksVVYRM8FpqFLJiLZYh++w/ClY/h4JkTdK+66VUzZATypez vLel5IHtuDM4pZKzYsITbHGhLHqASsI/FfRqkb3+hDzPpVUjuclYvdPYmcZOFWlmENS/ 4aJ3E4VB42QJi1sFCNmztHwFoYFGFUNeXL9d/1PkpAjHTJHsJYmJgUmVBxFSv4SnmQc7 XW13jNTZ3dGHbzns1IPzX0bUXK14N8VAafrfauOFuGDEr8SXirYusaugjTrbPkauHFN+ ltv9Qi7GJmvuVB77OzzyvywT3Xzi0UTE8J3P1hxfKylPBBdSvQKHhnL9FrUlBQfz4spF hXdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730404925; x=1731009725; 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=1gPEduXI+XMe6Dm5bWiV+D66hZVETOkYyz3aI9yIIqU=; b=CuD5KCEmYS1atlcASR9v2J6oiJeikeJ6n/9QXC8Y1xConvhMgxqJuTGJfj7E2Uomcn 6YrHNpLD7MbsSSI2E5/w1xsYBvg8C/+6KRWD/B+UbQE7hEyKu0DeevppASPxE76oAKab th3AYzmz2l3YYBs2ntWydopkPLxFeampXCYVWRzz1ZEr3rymtmSp8ikYXK2G1MoWKYQP obCVVOjB83Gom08eK+0wYX63/yyB5XLPV/5s4MvPe7WEy2+eje29+qOtzuIGl3EcYyqa RsF5qnwdG+KI3gU1NmFIfcQMIpFWEbJ7qAw7PB3Nvc4JaxrVSLKD/ogQSMGGC0sJhb9f 7hgQ== X-Forwarded-Encrypted: i=1; AJvYcCUn2pPLV4PXTp0szSNKI5StjUqgfD7/XbDneeEBs1DprcfCPyPeKcjSdfSNO9yqyZ1qAzhv2s3XU8W7rns=@vger.kernel.org X-Gm-Message-State: AOJu0YzaGJaM9vh80JcE1/fdEONSxXIvsku/L1cElSYQhuwczph7ruC4 Ap5NvFifEgiHI6NtePBloNy9YOSv0ETGA+nClyGJB+/BiWFbhFkQ9QktMII3BDq09rPiqndok53 b X-Google-Smtp-Source: AGHT+IGBYSgTZbJrlfDKZLP7kcrkgkxX/vih99iJkm8GYhF8BuKcQzph7Yrmgl8WnNkSLt5YSmea7g== X-Received: by 2002:a5d:6d05:0:b0:37d:4cd5:fff2 with SMTP id ffacd0b85a97d-381be764d8fmr3245266f8f.6.1730404924872; Thu, 31 Oct 2024 13:02:04 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:f39e:5519:d578:740]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c1189123sm3003993f8f.115.2024.10.31.13.02.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 13:02:04 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 31 Oct 2024 21:01:53 +0100 Subject: [PATCH v4 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: <20241031-gpio-notify-sysfs-v4-3-142021c2195c@linaro.org> References: <20241031-gpio-notify-sysfs-v4-0-142021c2195c@linaro.org> In-Reply-To: <20241031-gpio-notify-sysfs-v4-0-142021c2195c@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=MW68g60TEyuTeEqNXNwM1N7WdnOvX+cyTXG9bH58n2A=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnI+I3m8f03GVVwHU8kH4TDVsfKfCXZsPvSgUIR qUK4XATNYyJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZyPiNwAKCRARpy6gFHHX ctjGD/4uCWXLERvN+D9onG6oz17et5OWI9Qcnc255pX6RAb1J7TPgAeTUDIO/BYJ9tVvuTChhq/ Y3qyL7lerbZGw38TFPZufpRrinZvYhM2KOfgaMcuEf7PEMTMSVJCXIrZSwamMROCPhh56Ci67Kl DjKloeKVrPXJbx5OZ9dFME+JTsoGQx03uImflSuS+LQi/CcOw/wYBSnBMIBNrN9YPXfmfBYX+zJ 3+4ALAHwOLIHLsanzSJUAA3/xYkWxjtkWym+zhOjpkVeJwB2aWDubirBbKJpJm+uyIaJZ/lkrXN S6OEK7xonnipE29S+2MznQPRld2nME6bR+ZkcSI54usUybTMdUiMro1OnVOqSqRbfO1sYTOMepf Evz8ZcJ2LY8jVpBEY2bnCgavoSljHhTx815mhZuAFDfwKAy4SX2V3ct2INqXLOk1eQOPpPGuW4f N4hKoD8r7g3Dqi/uvyC60c/vCZXb8evhaqfiSyQAHJdNQGsA4OlJZKhEHFzAIMd3sGPvr6FCc5Z ipAt8LOqEkewZwWjb0XJI5acG2HPRtXS8+PepjXTkNl9HO9MGO0/IjTYMrK0gGYkYmDbXiPzSzp 5ONHqGgglXJtBLFRxnBl20eFkTAA1ypuxqC2PepBQ3c6wwrJezYLJ/Rp2Af4DBUgRcgg2zd5zre JcDzYtimkq2LtNA== 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 Reviewed-by: Kent Gibson --- 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 e6c1e26f302d..dd5e850c9517 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 @@ -471,10 +473,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 Sun Nov 24 22:45:45 2024 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 CFE5B1CC8AF for ; Thu, 31 Oct 2024 20:02:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730404929; cv=none; b=g8GSFDbgrFoZMPW7GldJuzmcVB0LjZPCBAT0Vw7CLq8egewoICsj5Sj4irQQV80kZaIc5ZfU6OivOyzzh1U8VBbrMss9tzk9EIsY05zwSZ27+JES87CVQRKyys5OhNn7HqQdeqK5gPkMfilysoicxOfS9yv0Njx/Vq4TgLg3A/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730404929; c=relaxed/simple; bh=LYpUIS6TNygS1bs1G3bDT7Wvnqt3+q3GyXXZY5PUn8s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OtAL/LdRgUwvi8BxQv92XtpqgsQE1vvvpiOyGv3iT/cHyEuaJcWcxEEtX49mTGA+OkCUaphUWcbUAAL/Jgm73Qps4NDrVR/+jCjje12BTL26FTFTlCPgiKP/PWEUfov1QFnhXxfUI+sDMnI/W5W55ZcLX6l6mE3RyJrSu7n7hEA= 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=b2hH9/9b; arc=none smtp.client-ip=209.85.221.52 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="b2hH9/9b" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-37d462c91a9so828152f8f.2 for ; Thu, 31 Oct 2024 13:02:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1730404926; x=1731009726; 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=S3+/PTENuc0Wqcd74grjNgAYyt4poP34aWyssLFyctE=; b=b2hH9/9bHcttljhh90MZfSQiZ32uxpV/1/zMXjivir3BoeFAKmxnty7jQqm395Pf7Z p7u/uQeaO8gxPx5TGo2d1CfegKJJhwgUVfEc+1LK0HKERE4rXQ+UFPejni8aAmVVrF5S HjWl+2RJ0F8fdTwL8Cy2uNi6JueGnFC6bJKoqQmavyyGHW92M/ASGWQXDUmmHmnl3lP1 USuhnQnL5ZjC5hyg4mh3be0DQTvpGFv0VwlctD7Hx0J4jzO/0R90+w14y0muIefDHpRA ELBeEuzDstZAwXwQLudi8+Nz33B30zMElnzUHu5FJQ0eukFS2i8PxkvaER1sQgO5cxy4 q2aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730404926; x=1731009726; 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=S3+/PTENuc0Wqcd74grjNgAYyt4poP34aWyssLFyctE=; b=I8wVeq3exkvOFY0K2xW0KZtWaGsrUfnZ7Le5pCPCsf7ty4GqJ/veDkoO1vNamUU+eY WylBzPAgeuJqdjWcYWZ8rGLvheOltg5eTIif/0uTAVZP/kEwKfegj6wQoUluJW9tFpd0 wA34A30wLtuQDCO8ULhyzyjmon68eyZvdvoXlvJpCn7jAJUyD+yp9Uly0q+jQl2E/br0 nRPoM5ff/CPwAHcWQavnjP+1eNqUb8lM3aYLxeFhZpZZ73Tijk2i/ZBQthdtYItny1Ku pr8symB74NHboxspaQNKGF3ixftnMw+hUj3Y+WjMxMSqcz61XFwEpRn29UlFBrhNEsmL WABg== X-Forwarded-Encrypted: i=1; AJvYcCVKN/Icr6tIcS0RKZOOvLMkc11bmrxpb5Wn3ugclgxS6FByx7DEo9J395R9A/U2RUlweL06k7gJIdl0EAg=@vger.kernel.org X-Gm-Message-State: AOJu0YzIKnud7bFbwCDdY+qbIOSfq8Peut28irIFCFQPOoNMGxnVaINO YVd1B6Q4kgydQwZOLN5FFjTJqUo2Z9OeCE+lAC7KHAPZzC/VY8mgR8xqbaI3m5c= X-Google-Smtp-Source: AGHT+IEmggNr+FEuZkXM1x0nNEKjGuUO++8XIqYVMGPsMqKP5Nv3ooR/+gyU7rfS3q5Ho1x6/Ve5EA== X-Received: by 2002:a5d:5482:0:b0:37c:d179:2f73 with SMTP id ffacd0b85a97d-381b70750d9mr5695759f8f.13.1730404926198; Thu, 31 Oct 2024 13:02:06 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:f39e:5519:d578:740]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c1189123sm3003993f8f.115.2024.10.31.13.02.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 13:02:05 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 31 Oct 2024 21:01:54 +0100 Subject: [PATCH v4 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: <20241031-gpio-notify-sysfs-v4-4-142021c2195c@linaro.org> References: <20241031-gpio-notify-sysfs-v4-0-142021c2195c@linaro.org> In-Reply-To: <20241031-gpio-notify-sysfs-v4-0-142021c2195c@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=ddPywcbmdK3xi5YOlUy1LjF/4WaHOEFU26L5BClPYq4=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnI+I3uiyYeJL4xbj/FYYWRgfQkObIqepxhrze8 C3IRb8mG2CJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZyPiNwAKCRARpy6gFHHX coElEACfsl0RNSaWVN1L4qPsEc6stxgG0y8cHF0NAGIWQF9vV42tAA0R2333wH5PCcOyHrOLiNi wdq4VWH67fJc+0cuD03CGjCuvzbxhTVJVoOfmBq6bz2s0yhrQhv+ECLW7EUQpKRudSSdsTRQYTQ 4ysRMJasmvSovf4dJzg3dQhTmseA7/DkfKO9p5kV/JbG0py8zNC7F4Irh6EzfUnUD43g/xuEGHh PU2xcWRaB778XYg2kVqwaQDGNNlZivAuY739UJEOEQ9Y9jovRCVmlrwegJCDKmIXYsJ9LS9f4DT 8+uUv/Ivr0Fim/I0uyri2ho+0cRFhn1tg8pWE69ff9mzAWvgr0BLHfoEjp1Y5VAeLVI4+iaOQbB sxs4c+EUNJkwD6eVrK3UDeTlqilbIOmdyW3AgEYxLyn3wiU+YO1bFxE04PwDot5xThs63u9Zan4 CWymhAUd9onDw+s2/IQDLKSU0NOx5C44mCg3hjTwnP0T56pcpJG5lZ9wmI1ra79Mj5Vu7dPpz+1 8kF4CsQJF62JKTmCie1i+afVjyAewuV+KGF8P4Rsvihu2d3etJFdYcVG0QUiMRr0ItuOqwt+Qvw x/VlDxmwS1b24B7zZFqh8TDE75T+lhVdU2i06rs6YF9DMzcwSzfFpmH1DG5pbBWq3pFGFGW/Rfu uAd7jsFyy03dTuA== 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 Reviewed-by: Kent Gibson --- 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 dd5e850c9517..49a5aa89cafc 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -307,6 +307,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 Sun Nov 24 22:45:45 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 4B0661CCEF0 for ; Thu, 31 Oct 2024 20:02:09 +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=1730404931; cv=none; b=cqBwdoH5RLNDrHaem1QpF5Mi8dchWAvpOQscqlAId4dChNlYfJj0yjGddvXySBzH445T13e01Tr4YKe2SQd8Cjn9AVRpQbWnaU7WOHkmfJv/NO1WDVmkHzeXHc20u79ASddGkAsu7AuEiHfmS5WHXRS7fHDKTFNJd5ASjSd+t6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730404931; c=relaxed/simple; bh=grXFaneMr1ISdxB6vm0ixLnCulIRiajDw5Hs4ZGd2QI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=p30kw5J6vpYOqz9UKPuVEs11igy9z2wV5J7uy5sxeBSkbwTsCHqCq/h2IvW1iv7wVr7RqEmdq8WPYMzWQZW8Vhsj6stfiDse8JmwPFly3cM3LZvkVuf/SoNL9VdafZ00ZJZy8jNlGAKMHm3rGFXQmns0vTpgjRoE/sLoGC9vgkE= 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=KukWMSYm; 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="KukWMSYm" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-43152b79d25so11629815e9.1 for ; Thu, 31 Oct 2024 13:02:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1730404928; x=1731009728; 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=HG0t4NeqbVLn85G3sOjEZke50iDELODkv6ssAwuGw0k=; b=KukWMSYmZAP0rQRob9dCMV93pkgneMVxONCqrE3ElMEVOCe0Oyl4YnCVYc7iLw4Ho7 KzJHTBznIQr2yhKI+F3iohjJnXM6YcXeUbfRbZra7jdYbxhcICd1c/QRA2fu6DLhxnDI IKS2SspLtmzE5PVE2Aj6fOk/N5zbHMcNqLXvkqY9kMy2uhTdNUgCVmTKd+Fe8BNf510d DKIjTuVxdbrNQ9OxV4kvESKM+KgYyd9iYzIjVQ9uu45kleEPBsGunm2mzePVrc2A+hut drQsmii/J2ECn9JcFuzRw5b4TD8E9RBLkTjZxPoWkHwIFvxc1EU4wlUjpJ73G+m7/wlB eR6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730404928; x=1731009728; 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=HG0t4NeqbVLn85G3sOjEZke50iDELODkv6ssAwuGw0k=; b=dZ3vei++hQ6xZ/92phGg08hluSdqMgq8QK/UFyQ5sGPmfxX1+Qc85Bt2pNJB3hxtpG CyUbmaimzXnsIY1gOBRVxaCu6G8EReBLTqvb/dUnU8hoONe8FnV+9vhLbCLKJtDngoLW gO+TD6c/paZ4aF8kFgBszGEn7aHSQxGK607BERb4Cw98+YAqCCXl5JF93BZtrKQGOnAz i9JhjCacd9JhOFQ+q57LkPwq+lFenuVkB5FkHw4zsrcORJw6XWl4gLdZKtMY4oSw3+q2 at4aK+1JivqP+gdTC8A7VrZQazvomQQCypqnmwZhe9JOAXemljhH6zdLIbmD9lFxnwIb J2YQ== X-Forwarded-Encrypted: i=1; AJvYcCVaRSli/MPACh0Bvy4k38UeryJznjabTBjFT0/myDQefCrZmKC7eaOiWsgRz9wIXUlLfjLVgnyhD5eoLkE=@vger.kernel.org X-Gm-Message-State: AOJu0YyAViuSapYI4psNr506BPpivWLsnW9MC3aGno7HXK76ssfNugmj +F6vN7VpF5zQDn9kxZLq4/GqsLwELaNi3vyYrcpbtVknZa1uOEU5D5N1uAg33pI= X-Google-Smtp-Source: AGHT+IFdJz3U9m7KPLf0+/MvSmAS4Ua279P5RD6u7ZsSqyiraKix7E62FxZs6WZVT7OQXDxf0bMwtw== X-Received: by 2002:a5d:64e7:0:b0:37d:49cc:cadc with SMTP id ffacd0b85a97d-381be7c20ebmr3290683f8f.32.1730404927612; Thu, 31 Oct 2024 13:02:07 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:f39e:5519:d578:740]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c1189123sm3003993f8f.115.2024.10.31.13.02.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 13:02:06 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 31 Oct 2024 21:01:55 +0100 Subject: [PATCH v4 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: <20241031-gpio-notify-sysfs-v4-5-142021c2195c@linaro.org> References: <20241031-gpio-notify-sysfs-v4-0-142021c2195c@linaro.org> In-Reply-To: <20241031-gpio-notify-sysfs-v4-0-142021c2195c@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=2143; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=VPwlZ8nGOi8NK4NOOYE429uUxxX6CyDyQfdMC7P82fI=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnI+I4WmYgaN7hopWfPfyg4/7kgpmKSho8uMiuI hmLg4nTrsuJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZyPiOAAKCRARpy6gFHHX chfJD/9xX94dUejypKQ2wDpArGCpy1bvkeHW93n1gGrPEIHITENtbuA7vJ/bVDI8pTXHocA6WuK oPPppHXRoqSZT2iV5Gx+CjftykF/fnHH0r8ICbZKa9hZ1vzB33XSlbAgLTR7/KZJLO+sZ0hMGzP ZiCAxXRpoR4a0x3JBkDMEiRqWUwXNcHkOeZBWNZTPfDV0KacyVWpBadl//yWM+c2QZwVYAFt3Fj YzWrZXNUNRlXHxXb4j7KxNOTx/xaaIulu9hHBOZWkz9hjNY+9EwocM4U5pUj8FzdgMKJd5VEa+o KtS44V4S+OjYJsHTFuNmmMzQnUhUrfZTee5LYCWTjn3A/K3wkq2lV4VGpC/3zA2+xI+eG3JbdGq cQP1DMVdS0f6pZX924SbP6fYGbnLqaKA2T+a5uzD/AZxpXjxu7SnAyEnbxKAwAqHB+Ufk7uzP5g NhhvZr9Wcx7CXy31GsztEf5J6GqGxkWhZUkeUvMRZ9QvzEkvHvoMj/qsUmNGVo91KUB+6ZMl3Ro CAOTOvIqnMhB14UAK4nCLlFSYQdKt9PZ47ztVNhfujHTNkcLYqfHQZuRBzVjeUR6/5gAkepdIlu 7pGKaVcfSK9+h0/HUniQQBgtIOovr2R9t9aJVjU3xt1XL0abW9tfJHt5nnGrJXMZqhHcz7CUvgm Y4G1BDstItyFFDg== 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 Reviewed-by: Kent Gibson --- 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 49a5aa89cafc..5d7e8e64783c 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -179,12 +179,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 @@ -210,6 +214,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; @@ -231,6 +237,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 @@ -282,6 +290,8 @@ static ssize_t edge_store(struct device *dev, if (status) return status; =20 + gpiod_line_state_notify(data->desc, GPIO_V2_LINE_CHANGED_CONFIG); + return size; } static DEVICE_ATTR_RW(edge); --=20 2.45.2