From patchwork Fri Oct 25 12:18:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 838858 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 89C3F1FF7B9 for ; Fri, 25 Oct 2024 12:19:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729858754; cv=none; b=pRN4QZUmL9iCQ2hiKdUDsil4aI2RcvSoyaHWjxNHiyrDymxancMpR6O+HscMPUwfUVtHS2WGEasfoTGz3XuUw8qfXo0RjFzyOBXw34sY82QMAQSbYJu0ZGU0oY368KZyJs3AtWU3HQWvwzcoDkH2NZKYdTNtYSA74TsXO3KKCmQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729858754; 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=qUmncCXFFl/gdYeJGwH1Rq0K5MdhpVVoYMCJ07k3ZAS/xOz5qtTedHs98BFsdsGLuuIUm2UUL96D9pP1xJSwVx5K6SsFsmpVObWXr/cDBpn9Q12CmCg9vq0ZZpchqaKYTyLjlWmkUgpDZ0qGSIK4QqJBX5jArV5kHLhj/wiSxMA= 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.46 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-f46.google.com with SMTP id ffacd0b85a97d-37d4d1b48f3so1363540f8f.1 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=kqaVlArWc5djzRlgq7pr/AQPztzISKR54wwC0LX0FWZG3fLBDGhPd7QyA7qGLdH8gU WkYYs3yrUunZIoe+sQiw+pascgdETND6S0fAhR2oM6LNHWCwJZWZVxckIW1RMQGxjqL4 XjE78Q/qUoAv/YNO+46LTEQB2FzebDGH+kXB/dtzJGj+YG68sLnB0ws2IQHCkIUbW6hl l778grAORrOtQlKiaNcTj78fgTsgXegBbKNwsuEO8Vq4j/I5eR1at2qMPIiTS0db5zCT ry1FFOqdxmHcxoKk9wiXa5QCgCHdLmfsQ/rMHPhhyTeiIsvD4DrWbM2CQja2tuZoHSzJ GByQ== X-Gm-Message-State: AOJu0Yx8okR6apRu51zYFDfDoqmGEja253igw25Y9zut4dr79x14o7fY Gab/LV6tKRtOBLFygslN7Eu+eercqQRC5bIFL2cupHIi7AShYuLNSBOuqSeQmn0= 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-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 = data->desc; int value; - mutex_lock(&data->mutex); - - gpiod_get_direction(desc); - value = !!test_bit(FLAG_IS_OUT, &desc->flags); - - mutex_unlock(&data->mutex); + scoped_guard(mutex, &data->mutex) { + gpiod_get_direction(desc); + value = !!test_bit(FLAG_IS_OUT, &desc->flags); + } 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 = data->desc; ssize_t status; - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); if (sysfs_streq(buf, "high")) status = gpiod_direction_output_raw(desc, 1); @@ -105,8 +103,6 @@ static ssize_t direction_store(struct device *dev, else status = -EINVAL; - 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 = data->desc; ssize_t status; - mutex_lock(&data->mutex); - - status = gpiod_get_value_cansleep(desc); - - mutex_unlock(&data->mutex); + scoped_guard(mutex, &data->mutex) + status = gpiod_get_value_cansleep(desc); if (status < 0) return status; @@ -139,19 +132,17 @@ static ssize_t value_store(struct device *dev, long value; status = kstrtol(buf, 0, &value); + if (status) + return status; - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); - if (!test_bit(FLAG_IS_OUT, &desc->flags)) { - status = -EPERM; - } else if (status == 0) { - gpiod_set_value_cansleep(desc, value); - status = size; - } + if (!test_bit(FLAG_IS_OUT, &desc->flags)) + return -EPERM; - mutex_unlock(&data->mutex); + gpiod_set_value_cansleep(desc, value); - return status; + return size; } static DEVICE_ATTR_PREALLOC(value, S_IWUSR | S_IRUGO, value_show, value_store); @@ -253,11 +244,8 @@ static ssize_t edge_show(struct device *dev, struct gpiod_data *data = dev_get_drvdata(dev); int flags; - mutex_lock(&data->mutex); - - flags = data->irq_flags; - - mutex_unlock(&data->mutex); + scoped_guard(mutex, &data->mutex) + flags = data->irq_flags; if (flags >= ARRAY_SIZE(trigger_names)) return 0; @@ -276,26 +264,22 @@ static ssize_t edge_store(struct device *dev, if (flags < 0) return flags; - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); - if (flags == data->irq_flags) { - status = size; - goto out_unlock; - } + if (flags == data->irq_flags) + return size; if (data->irq_flags) gpio_sysfs_free_irq(dev); - if (flags) { - status = gpio_sysfs_request_irq(dev, flags); - if (!status) - status = size; - } + if (!flags) + return size; -out_unlock: - mutex_unlock(&data->mutex); + status = gpio_sysfs_request_irq(dev, flags); + if (status) + return status; - return status; + return size; } static DEVICE_ATTR_RW(edge); @@ -330,11 +314,8 @@ static ssize_t active_low_show(struct device *dev, struct gpio_desc *desc = data->desc; int value; - mutex_lock(&data->mutex); - - value = !!test_bit(FLAG_ACTIVE_LOW, &desc->flags); - - mutex_unlock(&data->mutex); + scoped_guard(mutex, &data->mutex) + value = !!test_bit(FLAG_ACTIVE_LOW, &desc->flags); return sysfs_emit(buf, "%d\n", value); } @@ -350,13 +331,9 @@ static ssize_t active_low_store(struct device *dev, if (status) return status; - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); - status = 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); From patchwork Fri Oct 25 12:18:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 838515 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (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 0EE7E2003C1 for ; Fri, 25 Oct 2024 12:19:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729858755; cv=none; b=LFtl9aETCw5KoV0z8Pd5Zz9cQjyUgTzYIFpyi4TuASI4TIRWqKToeCaAQ3aP7nA8d0tKGVrDfRLfRU0ZwUEQnL2ZfCK+O8zQ8erMhhFfh+YtX3g3TPtJMlfatt3nTcRL2z/GukfiE+8I5UbFw71UBSmm/SdImzqrkAZROeqt6kY= 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.47 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-f47.google.com with SMTP id ffacd0b85a97d-37d50fad249so1411711f8f.1 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=K9G9rinyiT/aOjONTOcA72nznO960mUqH+G3j18/Arj/hCd2J0rzr1mcBgl5DsjMtV fuJjobPVNOgWvT2dRPSGjOSDOmXruAPRl350CquhnpxIac0HbIxlkQNkQo55y6VM8PXh 4iqmxoVs59roBImHpyT/4oqDrJ74EzwAPHn64Erj3o+ZFLUIxgH6Um8sy29ntkkR7qVW 6xHiOLcMct8arKOeSDWaa/vUVgYL8+SynN8K7e05R/R921zjajwMNy8OCIyn5sED3M/l puye5crhIhTd/ZM1bKEGrugoEKNDPItfq+3L4aM69SrDIb8lm9ZIYZgdYgbtrhCCOzks j1mQ== X-Gm-Message-State: AOJu0YzZx+721vXFChkyFlRJhxeDM8VDjHhBTYFvugy3tzeR0e7GSHo0 RyGIKjEIpJ8SzJc3q7TMISYSBJU9XdU9Qkt+8aGLi4c1hEeTfH3vasIUELM41gw= 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-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 = { int gpiod_export(struct gpio_desc *desc, bool direction_may_change) { struct gpio_device *gdev; - struct gpiod_data *data; struct device *dev; int status; @@ -574,24 +573,25 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change) gdev = desc->gdev; - mutex_lock(&sysfs_lock); + guard(mutex)(&sysfs_lock); /* check if chip is being removed */ if (!gdev->mockdev) { status = -ENODEV; - goto err_unlock; + goto err_clear_bit; } if (!test_bit(FLAG_REQUESTED, &desc->flags)) { gpiod_dbg(desc, "%s: unavailable (not requested)\n", __func__); status = -EPERM; - goto err_unlock; + goto err_clear_bit; } - data = kzalloc(sizeof(*data), GFP_KERNEL); + struct gpiod_data *data __free(kfree) = kzalloc(sizeof(*data), + GFP_KERNEL); if (!data) { status = -ENOMEM; - goto err_unlock; + goto err_clear_bit; } data->desc = desc; @@ -606,16 +606,13 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change) "gpio%u", desc_to_gpio(desc)); if (IS_ERR(dev)) { status = PTR_ERR(dev); - goto err_free_data; + goto err_clear_bit; } - mutex_unlock(&sysfs_lock); + data = NULL; return 0; -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; } - mutex_lock(&sysfs_lock); + scoped_guard(mutex, &sysfs_lock) { + if (!test_bit(FLAG_EXPORT, &desc->flags)) + return; - if (!test_bit(FLAG_EXPORT, &desc->flags)) - goto err_unlock; + dev = class_find_device(&gpio_class, NULL, desc, match_export); + if (!dev) + return; - dev = class_find_device(&gpio_class, NULL, desc, match_export); - if (!dev) - goto err_unlock; + data = dev_get_drvdata(dev); + clear_bit(FLAG_EXPORT, &desc->flags); + device_unregister(dev); - data = 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); + } put_device(dev); kfree(data); - - return; - -err_unlock: - mutex_unlock(&sysfs_lock); } EXPORT_SYMBOL_GPL(gpiod_unexport); @@ -749,9 +738,8 @@ int gpiochip_sysfs_register(struct gpio_device *gdev) if (IS_ERR(dev)) return PTR_ERR(dev); - mutex_lock(&sysfs_lock); + guard(mutex)(&sysfs_lock); gdev->mockdev = dev; - mutex_unlock(&sysfs_lock); return 0; } From patchwork Fri Oct 25 12:18:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 838514 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.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 898CC203703 for ; Fri, 25 Oct 2024 12:19:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729858757; cv=none; b=Cc6EtwY+RiKTBHwyZhrEpD7ycRnHh96N5IyI/hQrorZYNfzXOfPGxcpLzjJHrM+6jTEDbFWofLvZOb05K3N6vo4AtWM08UEy6mvLQPgZ84VUjlQK6KBAEKAVYrPne+5+lMqac+ckYVX5LwQxMTwgyPVk1n8ThiXsycp+SD7z4jc= 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.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="0nuryJVo" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-539e690479cso2061375e87.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=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=dLpoUX+aKqos89Zwdj0xGBskitUd6WXEf0JVqjJYCpUs6UAuBn/kjQ9e91N3cQUn9M wJlnmE/UDA99m390RrsOimb7S+jlZZ6zdMwat0ho/bUIKsEpecPvVJxsQETP+xUQVv44 v3D3bhbjS5BIwGh76ogdPPDYjd4C/QTgAZ8qdy5OXB+LFt3m9a9oiHcBmzJv0hGvtNw6 CE3GX+vHpF2y4qdGQmifRYUoZ8jU0UuO7uR24vGpHGQWMItJ7FO4iEtssjYKPXKymn6S DdX18C4SBGDctZLIMSNOMqxV2R3hT8t20elc9nsfrX++e1KtS9/pHNHrOFAXHWayArjr be5w== X-Gm-Message-State: AOJu0YyuUsALH0fv4XPq0jg1HqSexStYxc+Hls3G58hSFIp0fjTErBgm ruV2TsVjkWCzC8mxMo4AxeWe3dl/36Upz0MwJpaJjGR9shpf4Euqa2jz7u9vLIc= 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-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 +#include + #include "gpiolib.h" #include "gpiolib-sysfs.h" @@ -470,10 +472,12 @@ static ssize_t export_store(const struct class *class, } status = 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); + } done: if (status) From patchwork Fri Oct 25 12:18:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 838857 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 B23A3201026 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-37d518f9abcso1441997f8f.2 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=R6abq9mvENtXn3j26lERTuKr1z8kZsJA7tBGf0KzBSqRobYQc9MdmWrFfxOek8xvP0 EM1CQ/3vzjrk4s1mvVWU8CTEVQxNsBbazPQkw3q9zY7o8E8aHe0q4C60J6pHsuTjf8HV yVXvUSBv1/wjEzqVUCHTzcWFO4S2CsDQDnirjcQRXeBMGDe+EsiKkRSUK2Sh1RgtCr8E 3uFO3K718vFXeFi24iwvJ6aM99oIilGVNw0IgTvBhLEvh/WCSPErhkTp6l1X07fCOIVh vueU8LVTv2roBtUOBrDmKGwCWX//rkdYwKXcnTEH9YwQ098SNY/ACyPza2eVf+WMRcPe bN0w== X-Gm-Message-State: AOJu0YxpHxZPTi5b9jp5DviOayxFWcp6cE+QSrTGv1DuO5zKYJgFNqtL Xgc++hwV1HgjokxFr226eQkKZ/R6RN93VuW1v4o/ac4ya9LbJOOD6SDp3NizaDM= 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-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 = gpio_sysfs_request_irq(dev, flags); } + gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG); + return status; } From patchwork Fri Oct 25 12:18:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 838856 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 01DB9203713 for ; Fri, 25 Oct 2024 12:19:15 +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=1729858758; cv=none; b=EFLwE3qRMVc/uy5xtwvSAcT4Cb1dorBUvyLauYV4Zz11GMW8q5RWW3t+VTqh5RAaoLq20phG9H9zgSul30m9vYCWtYUqLfilJRKfs1IABgEBZfl1jNXPGvj9a/Hc2or92aJHfXtmAcTzIGG4NofWW/uloDQC7zSig7GxY1/Jv4s= 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.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="iVDc9yy8" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-37d55f0cf85so1526930f8f.3 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=Sw6p8RlnH7GR67fZLJWMfPC9iiP1ht1dDuJIfkOwdNVVDS77nssexZfsLNtqVR0X8t t00wuZOHGeqoOYi8J5e9aHAgHksvlbaJl5kzBaS7GyTcDIxIFVY3i1voZ1YnQfSnMlPJ ERUZXhHJI6uY4r2dPdvmRvAySwmRlo6nYMsM5kIAr3E2tSIxhBvTJNuJWnghVqKGQvix gdlluwXMWPaw/5CRckMfxD66Gvn6TS+8ENuHAq0GDZURRkqyH1CWQTnIJsvJo8I9P97E uOW9tNTLDaWTWLbWqX96wEMxOFsoJxRNOfYz/3Srx4w3BvaCnPWRW7PQLBLbM7SekNoY cE/g== X-Gm-Message-State: AOJu0Yxta+1cwVE+YGuZOxNrZsXudITr2z+NnhKuy0QfD1lTiNQQTZkj b6dbVNUnMhOKuQJw75BqCHwgRSx15E4I3rh7R6wtZcOzGG5P/J1asJNWvUowG0k= 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-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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; irq_flags = IRQF_SHARED; - if (flags & GPIO_IRQF_TRIGGER_FALLING) + if (flags & GPIO_IRQF_TRIGGER_FALLING) { irq_flags |= 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 |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ? IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING; + set_bit(FLAG_EDGE_RISING, &desc->flags); + } /* * FIXME: This should be done in the irq_request_resources callback @@ -209,6 +213,8 @@ static int gpio_sysfs_request_irq(struct device *dev, unsigned 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); return ret; @@ -230,6 +236,8 @@ static void gpio_sysfs_free_irq(struct device *dev) data->irq_flags = 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); } @@ -281,6 +289,8 @@ static ssize_t edge_store(struct device *dev, if (status) return status; + gpiod_line_state_notify(data->desc, GPIO_V2_LINE_CHANGED_CONFIG); + return size; } static DEVICE_ATTR_RW(edge);