From nobody Mon Nov 25 17:49:40 2024 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 81AD71E7C0E for ; Fri, 25 Oct 2024 12:19:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729858755; cv=none; b=g2hQk1jGQzTEJ369grBSdvgr+nDLvrmN+8xL4rc8GFdZzt9mCJ6dgCjpPIsuRM+RT3GIDkmiTk5GGBTfjvSg+smlWK5Xjf09uyMV365/tbJc8LAFrRG+Y6wBBr3IkMeddWbWVzDs1RYTcald6a441O6Qsunm92FpqpAzYK7v6A8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729858755; c=relaxed/simple; bh=2ZMPPBrPIR6OFsivfIz/Hhg/QV+K5tiWBJQ2SMqFVXQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HQTyn0ZTd0hg2DHIEKccPRSLVrADqj4Ql9zgzagcaHG+VMRXlw5vMDzVFPv0l3QZ83yUznIqu03zO1ABJzt5S28dlFJiRE3ZQKAW0AbqnkdL7rdsQfWiwo9vquz35vRnSSfgghWEXYQfdVMcZoAyaCdPB7KAYCrPz6AiRPakIuM= 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=nkPHKZyL; arc=none smtp.client-ip=209.85.221.41 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="nkPHKZyL" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-37d49ffaba6so1303621f8f.0 for ; Fri, 25 Oct 2024 05:19:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729858751; x=1730463551; 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=QWkyCSkH6r+vh7Zw7+g8GLRQLpunLm9PHHlFKHQOP/Q=; b=nkPHKZyL8zqgqanmIqazIS7wi19mWS7WAUbA8DJVcx2x4cu8zrQncYbRo99JwmupEP iMREWHT4v9WVEwrKXfO6hYFQoYoMhsIBiqGwrkYnO5SoPtkr1azleyfzt5P73UiVX/pC eyYKVygUm6wWcyTcWxfNC6Baj9rfPKI4D4oqGo6LtncVdKLCBqW/Km6HJspbP59dQtAM Vkj2kkYt3FqqL0L084PLCZCn5LcevBhgAKZ1hXsJmCGFeTzTxuj3MojYt45SLjQWEnMb p2CKYDIkstC0ktKm+Rg18OWfjx6cN9Jw327kfB/ZyLh6FJlJcLhnM3O/1TAk289qalRL x+vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729858751; x=1730463551; 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=QWkyCSkH6r+vh7Zw7+g8GLRQLpunLm9PHHlFKHQOP/Q=; b=qinuliW2rcI9erlS8+fk/dNX+40cQODNlQ+Y57hvHsSiwkxEVeunoBRAlhMf3lMnj3 Fl2GJ7z9gAXay6GbQEHEckEs2jHU6C3kfSGU9dw8Z30cHCF7H+XhoBxvKSQwBb7R9oDy 2g2QbhUlK6W0ikgM281/fnF9OIMnO5QPbeI2x38qdQRkYYDgcOV4VBHzkkq8f+XvMhta Dl5vm2fkQb+rnkxk06Tq03KxYAOoT5pIIClMo9cFODgrNdJPTZwAFR1rV8IdL7bBTwEm MuO1T+9vKi3PnFh2AOjsXKWBjmPxdFL6JoT0Mv0lY+F8eTEfsLByk++W7g8letylMZpt C6Ew== X-Forwarded-Encrypted: i=1; AJvYcCWol1PGzQuFBcuHXdVzPV/0pJXjCDZso9HI0z/xVgRUHJ7kzpiVVrm1ZcZYOrRKNo06dSQ6WdSxea3be8Q=@vger.kernel.org X-Gm-Message-State: AOJu0YzGzzcAOEiPHILqvPWlxGLYMWqokHAzJCIZmw2V5KTijKIn1jHK 0z+T7hDCL4rvPMniDY9SK+IGctNay6LfMpGgfEbwYMkRwZa924AlLlr7ByL01EA= X-Google-Smtp-Source: AGHT+IFG66VEZ7W+9XoTmQWsxRUyaKo7vGevjU0SqPe60IKsppnTLpaoZ8ob+knlW28WD5QWdZzehA== X-Received: by 2002:adf:8bda:0:b0:37c:cc4b:d1ea with SMTP id ffacd0b85a97d-37efcf93402mr5931790f8f.53.1729858750525; Fri, 25 Oct 2024 05:19:10 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:a207:5d17:c81:613b]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38058b132ecsm1388966f8f.5.2024.10.25.05.19.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 05:19:10 -0700 (PDT) From: Bartosz Golaszewski Date: Fri, 25 Oct 2024 14:18:51 +0200 Subject: [PATCH v2 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: <20241025-gpio-notify-sysfs-v2-1-5bd1b1b0b3e6@linaro.org> References: <20241025-gpio-notify-sysfs-v2-0-5bd1b1b0b3e6@linaro.org> In-Reply-To: <20241025-gpio-notify-sysfs-v2-0-5bd1b1b0b3e6@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=4315; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=QfhBP0l+q4VJTcBdTviOIrwQSOC56R7Bx8OaJCyJOn8=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnG4y8ZojQ0UAcqBduOQbwHRaa6TDilR5anHsc1 kKRvX0nJheJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxuMvAAKCRARpy6gFHHX cli/EACbHTxf5NyfWsPTBm7gbIK5K/IiKkVSPdqGpTKmt0ijvA4jYxcqmS8ceBrmH46QWymQ7FU t9WPGf9NEm6oU45LAQK/jp4RSgnJ3WAXiQs/j8Ia8OC9asX1ofaVqam1UjgzEJoOsrJTTcI9RHW Ol36ccQLyqkvDKCSpKcmGNfdWGLOAUIpUpf9qbhnwmFH3dTskz+tJFZ2clgHWX6LawWRHiRv6+H V1NMLm0pK0yMPoIImFof1jCOubgKH4HD0yylULY4yjj2/HUokU5dfLnXfCuQRFjIo/6R/zHIqMd SevF8cTBh/2HiuMIKSzDsY1ZYv1dQd7h/eVKkxr5EEwLWro8git21qj27pYTvRZSJjnVXiLWENN HO4twOsDSDQ/maWGngp4wCqMT4fTFLafH/vbUM5b19LhQ6d8hxqzvJCYmDmaxrfW5rkWDywHbgO 3yialtKzcG2DMNXL0PC2lc+qH1ek23g/0EVVh/a5Rclr9lQ/1ua7CpiWq1eDsOt0paH58345Yeq k117JOwV5QAiAwRoHbn+UEzj4sfQDBu7plZMZj7WvWSjyqGl06hJALSyrl4Cn8iW9Y8c3cUyFml c2A043UzrIEfHXYPB4JF0wzrlGvaIsVxmTJG0HJ1LXBSO6ZLKICzEwXwIluEsSv3cJaJFgTwRNG +n23nOCa3RTAN4w== 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 | 81 ++++++++++++++++------------------------= ---- 1 file changed, 29 insertions(+), 52 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 0c713baa7784..e11b322d8e72 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; @@ -139,19 +132,17 @@ static ssize_t value_store(struct device *dev, long value; =20 status =3D kstrtol(buf, 0, &value); + if (status) + return status; =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); + gpiod_set_value_cansleep(desc, value); =20 - return status; + return size; } static DEVICE_ATTR_PREALLOC(value, S_IWUSR | S_IRUGO, value_show, value_st= ore); =20 @@ -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,26 +264,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 +314,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 +331,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 Mon Nov 25 17:49:40 2024 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 E884F2003BC for ; Fri, 25 Oct 2024 12:19:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729858755; cv=none; b=eU4Xt1sz+wRNlyxgPAGPDUS3kvdajjX4NiuaC7iaXoePVAHkaNNyWUiEmUT0i2gH8WsfEqi0cPw+TR16CpPpb3Xc1TR+Pf6H7FRjRtJOJ/6xwyzbki13p1NWtHXu2cGa1Zp3XIPDhoXg3aZGH/5SgMuoAM0FFjTsRzQTHHwXeMo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729858755; c=relaxed/simple; bh=s/zWZNOpltjTQgPDkLMb/ESCpSOUcUF6G2vK/Vy6kws=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=q3X6ioyC3G0omePZ1OPhekEzB8Y3kfAEeI440xYDch8K6XlZs2qzZGt5urEJ+E1ePsr51m6FmKG3uoPSJtjzJiQPcWuWen1r+pyB3wJ1B37Dy824rqq1Snk9daMyWPUeHx4Cixg3LQFm4tCJic9EKXwDlK5ecFvZAXnGclzUMj4= 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=C/HW1igv; arc=none smtp.client-ip=209.85.221.41 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="C/HW1igv" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-37d3e8d923fso1257344f8f.0 for ; Fri, 25 Oct 2024 05:19:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729858751; x=1730463551; 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=v8u7wHoI6I5vyLiHlrP5BqxUBaWFX/5Pqb2gWKB4PZ4=; b=C/HW1igvKF+3Id2I2n9O1lgFgrA10Ki8K4gEX2g/fX3RxKd1qE3/bPw8KUN1GG3IUA ehOsDMh810iF6VS9N6GOO6oxQYXkczJX9KG2Cp2Rwdc4lxgNmNiaKmkZ/r+agob8+Xyt oiHp+vb/wrNTUi9vWs6ZbQ4Lw7dbi69uRiBBxCB2a6UWt8stqV9ydaCxTOBRA2cFru/T EV5OV20IhXt6aDzzpLlmQ/j6Z//YyvvzB7iItES92AlPkplrdc+BcerXa3b8BBwbTtCp aXcahl+Cxyfnb5b7r8dGUGibw1r9KIehfixUPhSfwYxa0VbToOofJXqXu/MIMFpPLvhU D8Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729858751; x=1730463551; 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=v8u7wHoI6I5vyLiHlrP5BqxUBaWFX/5Pqb2gWKB4PZ4=; b=oIAfGFafHv+E927X8mryhS/IQtJaGVb0vN+H+q7N4LZKc/K5O0wEW/BkpULMAcM84A OUtBIkod2fmCvVKFLuUmcJo3fj2bVCHq3qsCXUuRkcXf48SdHyFLEzhmHwejgasxR1Ja cYb1s7FkPTh3Elvw3IX4Rteby0euMX51iPA8ifnm3KD9qqes0TrpConPGEBCfewWWZ0o ffm4DbAlQgBykZjLRVFfEwq3+X9US9TWZQQTjykOIWkEkDmG/kcfF0rAwTOStg7riWbr saUAZ+hId8ZhvukB/QHzk58IuzvejwizyvNqZwrzjzl2PLCDCMkoUNiRWIUbaDdh+LTL 6PQQ== X-Forwarded-Encrypted: i=1; AJvYcCWUu/+8qgyoJFzyWQLDmNb0LjwabRuTAV5SCEhL134tFM9aQaVdAf9vokiMu5uChu9OYYrHswxaY8zisCY=@vger.kernel.org X-Gm-Message-State: AOJu0YxJIPHjdIVDWsrIcWY7KUEhMH8g38UCCzD7EkSRIvVUx/4PAWy6 w7xKmij+FLwc/p/26jjPtn7XGfMoGsEFDxcu1vdM3uwbJNZoUvDrhenike0E/e4= X-Google-Smtp-Source: AGHT+IHtdpdNKWD6DXd42kywbDL9gEe1sbhSuab5aaP+zfaquTM7RmR4AE08YNbvppwg0kPJtTn5sA== X-Received: by 2002:adf:e386:0:b0:37d:4ab2:9cdc with SMTP id ffacd0b85a97d-3803ac957f8mr4009622f8f.13.1729858751303; Fri, 25 Oct 2024 05:19:11 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:a207:5d17:c81:613b]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38058b132ecsm1388966f8f.5.2024.10.25.05.19.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 05:19:10 -0700 (PDT) From: Bartosz Golaszewski Date: Fri, 25 Oct 2024 14:18:52 +0200 Subject: [PATCH v2 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: <20241025-gpio-notify-sysfs-v2-2-5bd1b1b0b3e6@linaro.org> References: <20241025-gpio-notify-sysfs-v2-0-5bd1b1b0b3e6@linaro.org> In-Reply-To: <20241025-gpio-notify-sysfs-v2-0-5bd1b1b0b3e6@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=/q6I1rvAY1USpb6CHxAAJf2nHfni+nk27PyjShh4MqY=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnG4y8eMUg1ki4/vpCFXu6e7YZnNuUHA7wB1+v9 HMecdclMxaJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxuMvAAKCRARpy6gFHHX csXSEACfAsKM2SJOo00AHbpWKtA0/76AZCBm2ozLA4J/fkG3ES46KbeLvjGD8PeBcZoj2nj+2yA 92J11scBxnmgxPXP7iz24jBdvzxRG+bR3LqGDIbSF3qOZa/CKJ2ZFWQ8/cTJW77A7DAcrbNfBsC K4xqK4C26HyoxtJN4YGRxbjx0H9Vw15LWFtN38ikBpqJ89CqJmkvLfQ0rhcZN0sVhz8ViiK45bZ 1NkAQyEVAzbcqSGr2uim/oIijLxqelDTKk0dFj2X2m/tanBxSawSk/wOUBcCae/ThuEdykfwEWg dByDY8JS5eA/uti9gYH6ZfJfUVGIsB/nEdCvfdjdFDjxJqsDvpuHmWtZRhv7t+p74C/Muu6i9gR nFbkH7Zpk0HyDdW7MsF+k3cCHBgspJ2hScR0gXFZ7zLKz0LOaXe0YgDBYfgRGBjeqQMxWl4hnAC eHnYm6QzxAdniuPIA3qhrSlFEP5g1nfDk9zfiy+IzKArGI5UwqyFBqkbHAtLqDbZMti3s0Z9Gxo 1JqMQ5Z8LdjqlVpv8gmFEBAE6VoV7M2H4qfEde0V3nNjNuYnKU+hWYvUTJdF8+u0lN3yF7dZBgX q3NgaafjoihnPmmR9frsn41YT9KYqroT95N+VcebikxUOy5uT9ldaB2xXzOZqlqGXTQULVYK5Y7 UjOE7FvKj6jplZQ== 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 e11b322d8e72..a7a97458909f 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 17:49:40 2024 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.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 7DD311D54E1 for ; Fri, 25 Oct 2024 12:19:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729858757; cv=none; b=Lcuv4JwwuTwJNN47TsLr89OY+RF+G09uEpnEgv+YR42H3DEjiiRtWZMokVAl/cEUlcFLfXQTmFUOuvlrNsUqa/7V8uEofZe46irCGwZ7gSvgoHf6ZkrkMJQlO1/MmdPFX4GhEjBZvSmmaXL/gkvFy73ruM5FGthQLYUtg/Xcox4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729858757; c=relaxed/simple; bh=b54FbCHja7CBqwDRsM0h/GxRFDyS7LVaymO+q0/8ldo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HHwq6UWIfxPwlzLaHLHrpoIrYwG1kHsWDuY7yoi+x5sd8kyLP7l4h7zqLpIiQ/xXdiToObbLxec88XL8VVDfKGl94eT8KXMZrCqDakpbsQmm9yvGoNDbUdDV943lz7mTjfbx/LCV0DzKAWlinD7mcbedeGNQwFmxa9LnXi5sOi4= 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=0nuryJVo; arc=none smtp.client-ip=209.85.167.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="0nuryJVo" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-539fe76e802so2518964e87.1 for ; Fri, 25 Oct 2024 05:19:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729858753; x=1730463553; 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=X20tHHMbnUqEu6sXRZylXWkGDJY1IMTWV0MqB4dYN7k=; b=0nuryJVoa0VSgwnquX2moH6Hb/Ym78QF3uCw9A9CeHjWpIBJVFIMgRLCv7culrEvyi uGegS1PekZspdGs3yaOi+i4PspIfTYI8mmXS+wHi3v1O2tA7WdEwS0QqyxZsj76xBoch BTozPSpM1AGExGdsZitrmBcroYYjh8DLPnYjRVZ2pmfWGbZas2+LgnI7g5dasz6h6hQp 2NWJuUZkXsF0Q6gPYhcN4Ul3yqPte8DMyfp08UfR+P1aEtu75nHEq1vZsefzgNKXkcMT HMn3X3CFRzflgb9WMd/dNCZ6HS69J1ZIXUBIvZA7pUEFWc0vLSCmp6gwkrJftHRdC1mj cLOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729858753; x=1730463553; 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=X20tHHMbnUqEu6sXRZylXWkGDJY1IMTWV0MqB4dYN7k=; b=AK5qA476eVGvMTLF6nGGLJGNh5Wsp2QuTEIY94LOQ48Ru8qKopGzJOY1aNUM0+fBqZ PtHRzi4Gd9ML3NgPVa/04Pqrg7aL692AVxjaC3wL9f0VOKl6ZrYKIqgKDQmobtCg8R9l GuhtqEosRu2KQDbs10J/vbunQ9Yr0Ub9sTQtj6+PCOkg81QN24mXA44Fsaz0G6qB4/SX G+9pT3oXs8nU8rcDjJK+P+tTiWXQ7+i0LRTey4uwPDeogg5M0+vpVf+Tv0SxN+/1gFY1 3oX4eWd4sY00pPx5OFAqYAwZ7DI8nt4DacqpAmMM9Ub3ZXmh0ncfogpuv9IlPDxy+upi wITg== X-Forwarded-Encrypted: i=1; AJvYcCVFFk+ED3U6su/xr/wMTOdU2WO8e97xLxRawHMqu5qKPe25+NiAnSStIC58fR/3ip2oFseeygkhwneF4fg=@vger.kernel.org X-Gm-Message-State: AOJu0Yxu0xPdZ95FW1fowsuj8hGicqUgfOQsADTLWKXL/I5Wd3/zSTXS orHNpNW3W9K5s+E4jkYXdQekdORNhskNB3R5tS8TKDj72K8coauvxCknFLtKX5k= X-Google-Smtp-Source: AGHT+IEf0CJ7AFbjtUuLkSaxzxtDIxu0L9xxw1QnSt4U2kEM15dW177OkeDMaY9ld5gTG2GN+YZwOw== X-Received: by 2002:a05:6512:2813:b0:532:c197:393e with SMTP id 2adb3069b0e04-53b1a2f4e1emr5160147e87.11.1729858752440; Fri, 25 Oct 2024 05:19:12 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:a207:5d17:c81:613b]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38058b132ecsm1388966f8f.5.2024.10.25.05.19.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 05:19:11 -0700 (PDT) From: Bartosz Golaszewski Date: Fri, 25 Oct 2024 14:18:53 +0200 Subject: [PATCH v2 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: <20241025-gpio-notify-sysfs-v2-3-5bd1b1b0b3e6@linaro.org> References: <20241025-gpio-notify-sysfs-v2-0-5bd1b1b0b3e6@linaro.org> In-Reply-To: <20241025-gpio-notify-sysfs-v2-0-5bd1b1b0b3e6@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=ohn36PAaOtThoEaiMJhLHyeKcMLTYsApF7P9FlFAZko=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnG4y8Y/Fx9tT6sXbJSo718keO1nGX7qysfsyT0 GAjAZ1nj6CJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxuMvAAKCRARpy6gFHHX cp6ED/9iFL6wrmLovcDshjlQRLLf7ePciRMILB9z5G9LLAA2LZhG/4xAndo6VZBXF739EVPmPmQ hCOcpRjI6Gyhs1kIjZPO63c3SwNXhtd3kmUq9lhbiHnZCbKo0T9Uu/T9wKJnKK2CJp4G9c6ue+l uHP9Vbq9l2F7VGenRaBGMjQPykd2VQok1JbCKepdMjM7cM9U9AiBxIfe7xh8UNOLl6Bc43wEWiV eBuyoBFc6/fSyujQ+FGEylqmdUBun4rdg4akLXlYICt4BxxfJ+RCDHQyK+7ob4xP3kZTepRQnBO cBFvXEirrKLhXdKrRb/9cvOo+4H3v1/pMkLtcxOQf3spO9L4j5RfQ0OnNNeZI5VcaWZHBx7KGlj Zk9k3+vL2r1SL9NLcfYeFYOoz1rWiSa9viAEbyXOPYITjl3G/c6NIBSnonn53nJ+HRxbHdeC71n zlBewTC3qNpTVah9lWk9CgbxvXvBAvbC6LHz8SW+UGeWIU9X5xk+xHdTeBpINJ8DAOkbhqcEZQX tKovxMJglnNI9ceqJk1bRByCaIBN5Qb40uKmR2a9lgDAwxtuUmblHxJXsvUwKqLmgb3rw0Eydio J2jibNjK0Lh5HTk9EADFVrDab0pne/uARETJMULWDy51Y3Iz7wRKl0jsFjo8oa3ll5nSUWnyQwv Vxk9Yl/4rCo+96A== 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 a7a97458909f..de3ed75b097e 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 17:49:40 2024 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 B3CDF20265F for ; Fri, 25 Oct 2024 12:19:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729858756; cv=none; b=nlKkYAdNHubfxGRPoINf1hrd6gYtuhNcRKqk00kkRbshC0bO70D9LQwlJH4EjmPUrq+R1p5f3VAJcKiyuoqTVQGEaZenPQYnWp+hk/IB/7V6yNdvBI/PUGJmx5pntMJEMMUTg8bWoCsgdY6qh5mHlHuC4/gfgxf028YD43uLZiU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729858756; c=relaxed/simple; bh=ucXTcWv3SDdUKBqteO9n5MiCHQdfV5w44hqJ3hUrcPE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iDUz4PdEw6urvr1cOoF9tw5XqYRCPV3+MLyBkn+U9xatB2ZFYBHWdMF9pEuxUnndnhPqvJbnn2YvNWxf2frqyEHHyAaVuVtqE8TgdKktCm3Oj3Ih0x05vay7txPsaDsDp7zMn7yYFJb3Bl+G0MMpfqzLbJ2exm2Yk9csvCI9WRM= 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=fIpZ17Db; arc=none smtp.client-ip=209.85.221.48 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="fIpZ17Db" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-37d4821e6b4so1243479f8f.3 for ; Fri, 25 Oct 2024 05:19:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729858753; x=1730463553; 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=9z8ObF8lj4HxEfABv+8v8eHlun6BED31VoMO6tTrEo0=; b=fIpZ17DbTFEQG7AAlf6WY0ZSYP9GqypNYcDuwxfXL8ber7O59dCkevXRhT97Jg7DnG fs1EGw7HBO/VOyaDjI5bp/sI8p+S4mCeVwRBd3p8I/xx8+JCAafr7/k/cHPiyW6X2mHq EhenJidliST8S1EyMveZKxj8g6hARvgRRbKtLJhZjNJ5L/t59uhtf2rCte+8p1AMyDYe zaXZqajPjFjh/DJK+tzVm5hfkGE99yoSiZ/AHrIXIXn/3yfDcvtCnlCG5Ev3D0UT0dfW hBhrH75+wHYFJNQkfVYipqNYiJsXQRnz7wzcn6bj2rIb2WmkO6J8EdRIYHw6LI4WQwNV 0ssw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729858753; x=1730463553; 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=9z8ObF8lj4HxEfABv+8v8eHlun6BED31VoMO6tTrEo0=; b=R2hNTK04308uGD1cgqlpWBroGfQME6I9UFD7k1zLQU8jQT53RyRlCbl4f4b4MrUZ+E pK+t6bgrbs5moLg7iPWST9w/DDwo4f5LgJfYntR0pUWW7emplhwmSaZl0cW2fGBNSBTk Y0wKooYeXNit4BH80zFMs+tyvzpd88jk+/hDBU2S3CHV780t7uK5zUlnvXwpiagCTmt9 cg/FPQVnd2Hz5HCcRjTaD4i8+BLwJWEqL/S23VQh4Dy5cOFQmIX0bdWT8pF6+L669Dj6 Kzczes9vzNyqpnDuryKrsfF/ZhBhLq0UrD+erWM16NZ6+4PhbCvQtp6sdwMhU/TTzFKu j7eA== X-Forwarded-Encrypted: i=1; AJvYcCWNWr9aqMrSFKxRf/BvL3/De+4HET6vU/9ZyEGWq7PQ0gYnZBnmlsAVko/097BT/buq4iNNTnrsZwBAf7Y=@vger.kernel.org X-Gm-Message-State: AOJu0YzYvV7kScLm+v54fT0hXsOWXaPkZhPjVgSixlozxBt9b25lQKPL 5ngUI7cX8AXVNlyGrS97xdWB+tg9lozcB6xyvL9XPii7t2PFo9ueaEiZpk1mw3g= X-Google-Smtp-Source: AGHT+IFOlW1oseOey6MHCudKNj0cNLCjElZkafLvEvxvZHMGuGIjdc6ns3IEKegvlh/4OjaNMQ9gPQ== X-Received: by 2002:adf:b197:0:b0:37d:808c:afe7 with SMTP id ffacd0b85a97d-3803ac96dc0mr3651472f8f.21.1729858753078; Fri, 25 Oct 2024 05:19:13 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:a207:5d17:c81:613b]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38058b132ecsm1388966f8f.5.2024.10.25.05.19.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 05:19:12 -0700 (PDT) From: Bartosz Golaszewski Date: Fri, 25 Oct 2024 14:18:54 +0200 Subject: [PATCH v2 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: <20241025-gpio-notify-sysfs-v2-4-5bd1b1b0b3e6@linaro.org> References: <20241025-gpio-notify-sysfs-v2-0-5bd1b1b0b3e6@linaro.org> In-Reply-To: <20241025-gpio-notify-sysfs-v2-0-5bd1b1b0b3e6@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=ljWZ3loS3czmAqluVtTLT5KchD/gdIkhFYlUHezArh4=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnG4y8+1rcZHwMmA93rD3cL9ExCW+W5LxpxwUtr zPvSEcRC/qJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxuMvAAKCRARpy6gFHHX cj/9EADUC/6urE8ZlLzxj7+vG2z6DSOM7KvkCmv3QFPPF+MJUUx5UOeT9vS+/od4u9nZ7tlrlGc tcEuQySSshmJynMTrpUerU5mGxO7vMvlkUunI/2pLuaNBNNfvRkmogyqMHYADUxGHFm7LqdPd1o e7eAYll3U8kQn8t/caw7e3V5oGpCOWd/tEOfHL4NX4vRzG6uSgYYyOCIe+GrItfwsSIjgWCmZJy z7PpXAgdPkNj38odn94iv/1jSZUQIC3/7ZFxIguBChMip092EuWG4jZr1paSYEYfxo+E3a0f4YB h4jptlb/Ubr8bupvQr/hN+t4S96ObAJDcmjvEu/cfS1qIRbtDe1upKlftzzg/mOFhWlcXT5OQnX G0qqT2q3QxNpEyRYARTI4/QcM4StSrzdTgV3EQf5Zd0C2HhmOLqCg68cnqKiX/Nds3ih7krDS9r Em3GGFVmZeW4Q5OdfnwxvPPboGtdjkRYk8GMGLCf532HFLE6CjTtkWluoXz98uwjXZqUgn79/PQ iBQPYWFCtoUuWUPl78+ElLhDYv4yR3Q5Wb/G4s3O5bDhd6V8gH1kYRQeN/5u/T9GwmOfOVJQCa1 CFX3sK6S7RvyLVwnP/Iv7p44TNcfwK58yAh3Vmy/MPldmsPBJto6XhLL3nwYZP0FbPP5z4lUrod eaC6qF93XSApnhQ== 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 de3ed75b097e..cc5c51ca9478 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -306,6 +306,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 17:49:40 2024 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 EC4A120370F for ; Fri, 25 Oct 2024 12:19:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729858758; cv=none; b=SnqZtub/bEUQ/yaHEGn8enFOIaUXNbW/mC9KuUb7eNFjlg0Q4ES52mkw3xFNQCdZaJXLjnexDRDj8s2xwY5f+NAVFNzDeMlalY/VuBYy+/+ghFqDqbwRkfMs5A+PDggfYoI0RJo9Sje7V+72SB6a9dYZ4b+KmlWiAyG5gktC9JM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729858758; c=relaxed/simple; bh=vGacZSJsF/zEPOCOfp2fY4vg3hpQjD8RerqM2FLf0i8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=g2miAbZjBm9ZXmPDhXepIZutl9vEU4nppR97/OkdCqVN4Gx5ItK/+RkRD+rHeEUGrIP2ae9vdDQI/z+PB6t2FX/k1LqReNPvTnDBS5vWlG2EBInSD15twGOV1HALlCdl7rG+8GzH5LXI4iSK+Evi2hcOVlW18cJq3xNN+dqCq+k= 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=iVDc9yy8; arc=none smtp.client-ip=209.85.221.41 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="iVDc9yy8" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-37ed7eb07a4so1499943f8f.2 for ; Fri, 25 Oct 2024 05:19:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729858754; x=1730463554; 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=lkXhfQ9nM60iv4H/xHYROLBa8xfrajHImGbE7g895+c=; b=iVDc9yy85avPclPX8dBxrraV69yjwpYjp2i640XCwynL7fxNO0Q3KCArKb9DbNENOu qpP/6/9g3M2xwZsBMu5HFFZ3QejFA0bNuv2xtibJ5b0eo3/Zr00qXav2KRsYtxBwYN4z HDZC/5ds+6H5uXylP5G6TViIuyv5e/51ae+xT41pjmreN9E/CX8MUmlC5gIMmUhuoGIL ewbUiSOWS1IDETaw6B+FRb7BuSO/5nEz16V/l85kX3TAyZRMFUQSzF2NiR7FJ8FEKFoq TYYcFFeCOT39JCXdi8Z3a6Ff0CsowrUCAo/6fBJbvT807lhIC+IB9qJKL2bHQhhQWpOZ ehEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729858754; x=1730463554; 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=lkXhfQ9nM60iv4H/xHYROLBa8xfrajHImGbE7g895+c=; b=uHhXHdPuwsmLf3EK75z8DI6o+Bosx4vSgpp8OCToxJUEmy9RFsh3vdBr3TVLTrs/2r Djr8scsqIEIITSJE56Tt9f1L3Hk6BwncDR2JuNgjBG4uHinWHpWSCOBU/evvDtLhboDU Lji8foGLhVyun94prm76ajSQBakD25J8J2ClSvEgeBAdjk9ukB3BLewn3u4lF8uH/hMC nQO7DHDBzt9UihvhbizqRwbTriEtwrMDI/F+E4MymXhkgf0EisCzoyhi2akUOqCKe16P qM61tONSZ4ThWadNt0UfKxmvw3o6ngB1yL1N2o/Ecs5itwLpn4ATxQ87K/8+888UsLFz w08g== X-Forwarded-Encrypted: i=1; AJvYcCVbyTIgYqUwkTPjxionskGgmAGaPlHKej+nyVCneT5RLwL4j7sgFBYL0wjtAywr3gwMAy8bLK173opOqLE=@vger.kernel.org X-Gm-Message-State: AOJu0YwHpI7c9gaEJhtp//RL9UQPYl4XtXhxZwxyoTsbvnxgwMLsTmim oV/sCX1q8Uv5eer8dWogF1HdXJQ8niZfT20jyEr+sOHTwonnNSOSoBbyJ61FOtU= X-Google-Smtp-Source: AGHT+IE2tXt2Qer18t+wkhSxAxHD2caHuxLHzHS1zu2TOmYNonvrqSJZJIeBGjAkop7lbDUz4Mqz9w== X-Received: by 2002:a5d:4f84:0:b0:37d:524e:9431 with SMTP id ffacd0b85a97d-37efcf92886mr6259120f8f.57.1729858754237; Fri, 25 Oct 2024 05:19:14 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:a207:5d17:c81:613b]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38058b132ecsm1388966f8f.5.2024.10.25.05.19.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 05:19:13 -0700 (PDT) From: Bartosz Golaszewski Date: Fri, 25 Oct 2024 14:18:55 +0200 Subject: [PATCH v2 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: <20241025-gpio-notify-sysfs-v2-5-5bd1b1b0b3e6@linaro.org> References: <20241025-gpio-notify-sysfs-v2-0-5bd1b1b0b3e6@linaro.org> In-Reply-To: <20241025-gpio-notify-sysfs-v2-0-5bd1b1b0b3e6@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=KEBKmL5Mi8XWBz+1StVeG7MRKVKk3MzCpGTWbbctQO8=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnG4y96DCODDSye9DZO0Oi3IwIep2yJrN6mlBXk qsaAT+cf1iJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxuMvQAKCRARpy6gFHHX ckqXD/92s3lNaJeWMk7N4OgOFtmjrvlE81T0x8hTutmv4Enkn1WkR75okUE1gZVMihVmVP8slTc ZHX9ZkJoojMcsLXIeIEx62mA9uE3lHHKJppHCEAo0R9JOhpQEQMVfz14FGdQu62FHBUC0LNfwV0 n5H2g3j4Mc0OERpNOABocWTXj9hFueqHlT3PK3m1rgAenlQ4c0E2P+ycdhVgExBG1qP4kGIWu76 f1dwsouCJvLuGLJBHth6cmAzme0mHH+7CHVskViipJtno0McELQptlEZsSVVvcYLBY/wOLwWJpt u+pu+upg+gb8Y2ewNaeNBVIlcraNapxGQ0KAg43/y4lRL3iUSV/iGZim3fVE3ijgGinGtWFxb65 aJRJjYrtjhG31W3Hev2FL9EuzuegAzIZxERLjtQi9nJ2/w53gOU2Vbk9vhBAoq7i3v7ILZdRU8i eD/uVgHD9SVmdrONj9ZP7AQ/FwKb1LfT9xHC22RuXS+0fA/m5Wh7fKhnLCgbhYQHB22QwqpkCNI Q9TK1lMC1fwD0RRZqQ3sS/TYa05wsi10yY1Ur5XVZTDKgNXlYM8OzhuDkZ6P8qZB75DAr2dzA7i hQVH1qoL5WZ2Yoef/okwJMM+cF49PpVDqXenCb7fB6/svV50Y8PlDEmqaKrU7N4rOxwGhkgQ/t2 65dsbVomjVn+7Vg== 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 cc5c51ca9478..5b7d65117d83 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 @@ -281,6 +289,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