From patchwork Sat Oct 26 12:58:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 838850 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.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 00F951D516A for ; Sat, 26 Oct 2024 12:58:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729947522; cv=none; b=JQT5TQ+9S9D64MgDvvXo6bFEAhrb/WPnybkSAfw8dZz3OZUoj30cRUC5D6kgsQyg1JCEvy8QpTb5li6H59Cp4jdf9BM7HnKA5smLKxoUrwri1FPUgzisNSv7G8gacsL+8nmVU5FvAFNJQUdSyrA1Nrzq9aH9Jgy/IwOBSvAMdxI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729947522; c=relaxed/simple; bh=3eGsWj3tldB6ErshJTowvNjw6P+DOV6RwonJQjhOJvE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=df188lJJoIa0i327DNvHWCJYJAhNexgtOVzeQyfKlE/DkHjgj7GAk325qghhph4l8J4l9PUsAIZI75DaiPTDXPvf3z95UTFzb8a0E/ojZ36Z+opZ9H69qf/cxPQ102sRiAhrD+O54DFojgfzUarnhJtuv5tpnUfz8Yd8rEJ1HgQ= 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=znc1qCEv; arc=none smtp.client-ip=209.85.221.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="znc1qCEv" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-37d533b5412so2018957f8f.2 for ; Sat, 26 Oct 2024 05:58:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729947517; x=1730552317; 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=znc1qCEvoqvZ4X0OUcIqNH1SYNHH/QAzD1uOJn+qGTjUd1AVzqHsdWqhm+RkokxVup 3gp1HoYs/MmlkIH1yPpFGDeLHRAYMytS69xtynz474SI8y5ZR+isjEnBZVnSLHJSYMjz oL8FLCecxHie26xL7YOWktne53FUiyXaulXXNms1YMJqNF/dqmCsjJXWf3Defg0LF6iI 2m4m58dQLdQBha0WPk3oSulOuDkkWJ5RLsuQNpi5V2HRkK0H6w73rZTcawYwpAAhvTVo FkiSnQCJ+z/UaU7RJSq+tLgVx5wcmDiHFOMY+/IQQuWUPJNufzSE51vDMg25mwtV2+Ve ld1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729947517; x=1730552317; 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=UIAMKcYc37PhXkgDFt4NRVVid0cD38NVPnLD6Ws32ivA4xRQuasx7jAcAuT/H6WgbA o+O3gb+lJMJ1/KszrTY4SFnpFTyMj6pyu5ZUbsmYKsl5NBdRjIbQYr2xcNbgb5W5UJHF 9Oo7Wfkv9tUjdJmjNWfyZeizSYbrBmB+lX7VobFkuWqgLtOiSOWxKtjO7xRA7QZC6RpM F4c9nyllzfgj6NewxSUSiDGvSeQ2rLaFAIwS8QfQYv17dD2DBQaD24JlcmUMY0c6MKk9 TIQa1eEPC6k+EJPHd4RFMGwJiXVJ78DB2UPVRxOTc+9dZAzPe1bswDTXCkUPwBVKbLwL JcEw== X-Gm-Message-State: AOJu0YytPAxdPGwNWShsujDRdP86j2zIfk3ykRGWIb4v1e9dwx2KbClS w34gBJoDTHBUd+nh5m88gTX2u5je2qUocPbzNtBxaXnZ8LqJR90BM7MVl23zbTk= X-Google-Smtp-Source: AGHT+IETMsEh1wTvqS8LLJnAJwH28gfAqDThFKMHmYJMNVRiZwJXW2BEj+wAiY4AGsS1xAu5l287OQ== X-Received: by 2002:adf:b345:0:b0:37d:2d27:cd93 with SMTP id ffacd0b85a97d-380612008dbmr2013077f8f.43.1729947517114; Sat, 26 Oct 2024 05:58:37 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:617b:5770:df34:27]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431935a3edasm47498535e9.22.2024.10.26.05.58.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Oct 2024 05:58:36 -0700 (PDT) From: Bartosz Golaszewski Date: Sat, 26 Oct 2024 14:58:29 +0200 Subject: [PATCH v3 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: <20241026-gpio-notify-sysfs-v3-1-ad8f127d12f5@linaro.org> References: <20241026-gpio-notify-sysfs-v3-0-ad8f127d12f5@linaro.org> In-Reply-To: <20241026-gpio-notify-sysfs-v3-0-ad8f127d12f5@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/ZANAwAKARGnLqAUcddyAcsmYgBnHOd5bjJcj+GPd1FZ33MueHhu6xmJ7V4uOy77a sc4MtpPwFuJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxzneQAKCRARpy6gFHHX csWnD/sGuWJUMMr8NI/gqHr4VJ7U32k6j6MffItGRvD1/2nQneCDDv/LUQcTUDVgFUOGSviWPj/ /Ykk2Ow2uEbGUaT0tWTMCZctE3eyU96jtN+G+LBCYJBRPMkIn1cW5fnw0A9hKiHMAI7IeTkP/wH 7mFCKUCJhmrnOQE7XeGXFA7a6iSSBu4jUq95YhNbBHt1vMjcntd0prHXF9VhWpZ7cehzWDvPSIw naC1Tj+So/1x9JMcS2S37IK+jZhTd1UHw1ticAjjaNUs8FRd5CexH1MZBXqzaQKBPRBPaXzEbmI 8r6whB8QWwgkgG38ziXL/hqe8xgzbgfpqxueEnWtQaD56qFSy9BFY5dML/CdgIXA51rskgiDD8H kzJr3tyIJ1liXScGqaACA4B7JPWQ/UQ0K5SHJYqBI5MG+1nasQ7hrcV4vBgqpm/H4TM+2jpQFka 4isjaCwFVqK4Mn9/fPCfzxpiQCVYNn8VWARDCmIxV6B8Og7ZTQ+dL7vtmfT6/8MlglSDslxdCxI iWR7DGAKUhIkDr7IaRE/HT75eE3hW+eIYfWQErgVK9z+8AbjrpEfr653wQY6KIbyQTBPh/qO9bH I52rPaA5owg4jOEFeaWnQdjDYEIUHbKa4iVn41+pah8y2uxi+CbFgijGERE8DGJW+qqnkaosVkf 72HM+/n6Gc2K4Yg== 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 | 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 = 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; @@ -140,18 +133,17 @@ static ssize_t value_store(struct device *dev, status = kstrtol(buf, 0, &value); - 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); + if (status) + return status; - return status; + gpiod_set_value_cansleep(desc, value); + + return size; } static DEVICE_ATTR_PREALLOC(value, S_IWUSR | S_IRUGO, value_show, value_store); @@ -253,11 +245,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 +265,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 +315,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 +332,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 Sat Oct 26 12:58:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 838849 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 C005B1D54DA for ; Sat, 26 Oct 2024 12:58:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729947524; cv=none; b=CdBlK6mzVHzM9mfo4BV4TrVb1KWwS4z+ncK591G24IE5h4HaHsDhBEJcDj3glW5p0RJbvaE6ba/dAYvoBXdEeH0j08O66XqkYu+ejQXzboLK8ckDmnGt0dnNvlJCEh/8zqb4sABcXtMcWbgGchfBR308MDw3cWt7GD2grRUNbck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729947524; c=relaxed/simple; bh=HropV407um4f/G9t3Xi5TzE5XLHPWiScIS+b5zddSj8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ev5lAEmfjWnaOOBAeUZ4//14it8ACnvEPQlzJcfqN+WuR+XJf9PLuFrvn2H7YVnUYAawtA3CmzOZw38SzeB+aahVMFmHoUQ/jsdsoAPMNXWNcAq13iQl8RPUbkeTUwwAq8NBBHZIVL6QhtPjr5F4h4H9eYcS53ZYLQMK8L/b5e8= 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=LlcBlX+E; arc=none smtp.client-ip=209.85.128.53 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="LlcBlX+E" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4316f3d3c21so27418845e9.3 for ; Sat, 26 Oct 2024 05:58:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729947519; x=1730552319; 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=YE8cLxQdEVDeLv9MNCBstLWMA/Z6NqCZrkQPPjSdQdE=; b=LlcBlX+EUKH8azPaDWbsSPasXYl0YOOlwaG2fl+0zgKdM2m7XhPt0nPON5XVCkXc2p Kknka80IDEfzaee2Yq/mgUCXPmSCxOMwf7mr3ro5zJAOghd61AVgPzC3wrjn74Jxrs57 oWFx6GerLyz9kjQyLk8MSJR1u3w5aBuFbUdZDDeHdgjwcosJH9g/cyIEOsgZoRV0Zh0g nj/jGorbVZk/WHj4+ED+a1POaTpjc12VkKURlAkYXwWUJpvKVfHtEUhTbfrWt3HzVui7 wLTHuZBTqSrxv8+bc5npRYw5p5uy4M/+w/qMUFPdxE6wxsURvXjAhovqS9QkHABK2Kr9 4WtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729947519; x=1730552319; 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=YE8cLxQdEVDeLv9MNCBstLWMA/Z6NqCZrkQPPjSdQdE=; b=bzGNMHmz6Bmn4qZWmyKeqD2Re01WNi06LPX1+rm42/hduwbPE+g/at3sjPa06bsWKu 8d+1OZ/1wSSSuznELsNljxdb2C8rPhuX3mW4KFF+8Y3yznlacRx5XQvPiApSn1WuKk3S al/aaAeiffdGf0EW1wSo5Bj4eyE3ujXhEixgl7E8453APVGJ8w4/1HBRTSd/d3moX7JN 1RqQWzmWN4pflUFLPedjScBgDP8PCkL1LWjA7ZeIy3VKgyVV/Dkj+ZrhUrif9jk8ADqi +jdy5ELCHyQCldqz/I1Adhic7TIebrtY/2s8KRmCrDCQ7gHWwXQMMkEfHJTTGcTbczuu u19g== X-Gm-Message-State: AOJu0YylKDztKCVOE7ruZeQAIeGvEbqIQV36dBe655h5Er6D6+uvFTcY ab6Z7atwz01NYlGaD7PApq8v+A09gv7AgB4WjsaoGfLoxX2xMN08MWlsQtHKXN0= X-Google-Smtp-Source: AGHT+IEnIrHs2M3Ri6ND/0ACKvKwENUZziAR+IDYzheSZ7MtKalmSu787M2k8JCTlFAL4S8HKgF4uA== X-Received: by 2002:a05:600c:3b14:b0:431:60ec:7a91 with SMTP id 5b1f17b1804b1-4319ac6f895mr21633785e9.2.1729947519143; Sat, 26 Oct 2024 05:58:39 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:617b:5770:df34:27]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431935a3edasm47498535e9.22.2024.10.26.05.58.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Oct 2024 05:58:37 -0700 (PDT) From: Bartosz Golaszewski Date: Sat, 26 Oct 2024 14:58:30 +0200 Subject: [PATCH v3 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: <20241026-gpio-notify-sysfs-v3-2-ad8f127d12f5@linaro.org> References: <20241026-gpio-notify-sysfs-v3-0-ad8f127d12f5@linaro.org> In-Reply-To: <20241026-gpio-notify-sysfs-v3-0-ad8f127d12f5@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=dl/3eJiyQ7+gqXB4o2UfBU8KW4Ret4Run1NBj9XzUYA=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnHOd6Np20PQ/LpcTx9IIOLDfWKkRigviz6stDr AdyWXXJBRyJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxznegAKCRARpy6gFHHX csywEADYbhXvEw0KE8nTPHezf3eYhdiH8rHBFDB67Jw90cbU952EjjfkQ4vaBD9aSp1bh1jgAIv BiAfZhEqfJaeHKiXSs26VRN/whc9I/V97TzdrQTyEzVdC7j2zrDHtaM4DL1cRmfPgB6B8WyqD7O waaW/c4Jf/+9eWCfbzT0MhGRYvQUlY6oKb9nZum7M/Dv7W4Jfn2j/wMURjlmWVk9E6wenNqaS6M DKT6NLAm389YeuPlrFoSQxKydYl3DMOIlHZFl7XBVBFHQrFetv0g3uy4UVdwOMooFzLXa5x8uNJ ylriWfMerXL5cG6a6/4sor2hvN29HiuCVu8H+V1MAeWG9b2CeREVmHFDV40u++q32E+ThW4b//h uHHYOSYzVF5LNIVrwHsqUmslPSsQrY+JFcY6hhuviIlhMMFjRfygKdXXVF5e3GNiD9NajMtjDrR Ms+xXr7GWSJBcUYVBpHRGUqziMcMxKwcAe4CiSq2b16vqAjyNDlrTmK4GkedILZ4+FHADaOLJe9 RXO9Yeow83nqfHFFgXJvoopdoJMsFFjSa60Uo9HqM0qA/nFR4kk0KaPFzH+Tn59sr1OaE7aOFBD bGYhxisOvJKZ8+7cCf1yAIiGb7KftSc4LynvNfkMEPFgT3yeImmNKOn5XXm+SwV10xH+DGzA6c9 O3ss23pESVnDD9Q== 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 a0926a1061ae..72617f929a2d 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -551,7 +551,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; @@ -575,24 +574,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; @@ -607,16 +607,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; @@ -680,36 +677,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); @@ -750,9 +739,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 Sat Oct 26 12:58:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 839056 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.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 0CDED1D63F4 for ; Sat, 26 Oct 2024 12:58:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729947523; cv=none; b=kene84lIyZs4esQLnCXV2Yj+GOiynR6x8ZJ+K+9x89FkseHKSvXwLSKR96boRpSM2L5AJT9ia8vRi31Yg9FAt5hkhTpHZnHTnWPspH9dToDxGMg5pxcdRMvibCUpXC0QiULh9YDRBj7eaiF0xQ+Lul2PtUUqeEEaqAdUUELGLIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729947523; c=relaxed/simple; bh=0QewVGxhisfsbuORbcYiI8x9rkEpWtfsWo4kKRmeYow=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pZXsh3CQuXmWVYd3DDvCRYLKgbn9LAc1BLHOdwU9PhF/zX9EI8/cgBn8r7aN7PQ0swyWZjXSA9nBINLh2egb3GIFvNd9H/+1wT82dTL13nIUcp3lx5a32wsYXjZC7z1Mqtcmav+D8/IR2pTEMu7CV8JsEjPzv6tZKQKJZ3yXX28= 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=JGQowBE0; arc=none smtp.client-ip=209.85.128.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="JGQowBE0" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-42f6bec84b5so29179315e9.1 for ; Sat, 26 Oct 2024 05:58:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729947520; x=1730552320; 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=Srd6xXt2v/gBTMIhpSGaiy2kaKtuGZrnXVtWyZIMWoo=; b=JGQowBE0Gxh0hjrgPJXRrWlx36PBpWbx/Vr1IfBqDIGPUG238/pOCK+eZHDJhiMcjs D8Zp6zl5oVRNEaPjVomPM8qbgrS7lOXoIjJQz0f1AfI9AmglGIWtDw0gzQ9+QVhr+I+V eZhZ3nLqEdWUP8d/W44cKE9hdLWciMFAsVOHWjgohzvwGbsEfvNlS5YpujFEfN1v/I4A MOtBPHkA2yizXiz4DgK1qW8gSSMgkjpXFvCA8K5ZSkQuCBtjghNi9QXUWujKvrFNyR4W Hbx3hD1sLvpeBqpFHc27eCoXfTjr2JiGPGuSQA5xCOqrqpUDcDGIXlJkNJVwA2rRkxJl lNoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729947520; x=1730552320; 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=Srd6xXt2v/gBTMIhpSGaiy2kaKtuGZrnXVtWyZIMWoo=; b=NmINu0zfJrfRxWoSBsGBsuqjXy/L29GqPR2ctxm+aZ+WJYBSIp9m1I+gUtw8iufD8K KKNksfPsa/PevyNISnWgM1H9+e4Gt7vPPZs17r426IYXHEgvr1V6n6qDA1ami76zc1Hk 1pCJVCDTf5o7JSu9HStxTi8EWEsCjfaQA5Sty62t6WD+sTkB4RchlOWZ9GTAyS7IWaSX 5qkQ8MeDHGEQEDZpS4JO6iaazIFycunUpV6XoTgcau4x9vadDtyAsVWC10jh+9qC8AOK hEnFeb6O8AlWWFEJRB4bp7fa4OHccsNwnLo5nPNNYx9EEgR1nBQemKHzjNTvhBHEGIaS POZA== X-Gm-Message-State: AOJu0Yxz4IK31J2/5UTso1eJDwtv9jX03EoLaQHsaAEqx4pPs9SHcmUv ff1WG3z01sDiRPA2YKaSEDoXCNYgPL3Hsc5sqrjT/t5P/N2myCISVw4G+bSd4n4= X-Google-Smtp-Source: AGHT+IGWHDhy7o0qBkG2Wr8LQqEtvotX3tdVXOmBd563NA5k/6+y2u2ytNwuIz881WXgje1qmpjGsw== X-Received: by 2002:a05:600c:4e8b:b0:431:40ca:ce44 with SMTP id 5b1f17b1804b1-4319ad34a44mr18180445e9.30.1729947520292; Sat, 26 Oct 2024 05:58:40 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:617b:5770:df34:27]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431935a3edasm47498535e9.22.2024.10.26.05.58.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Oct 2024 05:58:39 -0700 (PDT) From: Bartosz Golaszewski Date: Sat, 26 Oct 2024 14:58:31 +0200 Subject: [PATCH v3 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: <20241026-gpio-notify-sysfs-v3-3-ad8f127d12f5@linaro.org> References: <20241026-gpio-notify-sysfs-v3-0-ad8f127d12f5@linaro.org> In-Reply-To: <20241026-gpio-notify-sysfs-v3-0-ad8f127d12f5@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=Fz1+WpmTJ92C+0rFC7RuiR9W6klOe83EubtpT2rv+ho=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnHOd6FBgaKfCk05jU2q4Nz0LLZshcVpT/CvkYd ZS2p1UhCDaJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxznegAKCRARpy6gFHHX cmGgEACVCUsJ47lDsU8BgY94zc5DaD16/5LzyWYKdutNy75AckT51p3MalKpY3tGOEXfIKQGG5R 6y3qv3t6LvVTRDe9vf1vWrQHiZgpeXUt0KhCsgN2b2dgPGNkSJQbFqJASZHRi/7qfXvLfZ54Ua0 UEPwtQ2fFnEfVr4WZkQ/Ip5XZekUh0r6G507M29mXQhEhe/gi9MUVKh6R2Mn8qSK3CdB5ll1dYL 4ui7x8qLH7TB/XZfadaHx0tP0W/hz/ikufp7CaZAqobt4BRPKYqfC9JwWIMt1NX9Pt6S/sa7MWf yxea6YJanT10FTcqIdgneWSgBzzBtLrq97b4w6o7i/yxqVW45ns6NAsiMLPNDh5OrtzTS2tTJJP mtve7114DBM82JXaLQFUxzU888CJn+MTxa/xaJ6LUxnxbHxKPGeqee+5douQzXUeiGssZYQOcpe XrHeNICZDypIP6xx9XXHuEjIAIdiweeKq2p4TTrpLmaR0rtKhcCNMjhclNXzLvy498v7Z7ac9K4 7BLCuQZttXfgguL116HKb4s9oTDUyENwFg2hY0RDWDohbDXFT1B0F5RqB6MH4bH8i9tGAXFISj8 4T4NNcUSyGe5fADF1zWjpDJLsU48uCsTUxujsd77oQN4UWbhRiaGpC6iEO9lrF2tGloV5x2rvxs rsnhnZ6/Td7Rr5Q== 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 72617f929a2d..e1144d3c7645 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" @@ -471,10 +473,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 Sat Oct 26 12:58:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 839055 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.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 043351D6DDF for ; Sat, 26 Oct 2024 12:58:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729947525; cv=none; b=G7aUkNf7HTg8PQRIUAu+DyqcT2Ain4rYplWyMmXSLCQWyJPtybJAPsIRX99fCku7sCftktZ97j3jfkxnN8wf8oVp9dIgkt/LRjaeKle7DEN6xkeZ9CTo1789OeYzRmeCwI+XxTV2z8/WR/BAPy/M4jqvXIvEpcU20oOEAIBRi4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729947525; c=relaxed/simple; bh=Huooi3brujfQJQF1saq9mAR4WMheDyMLjGG+ih0fZh8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=H3lKVBEBeT9mc7/bBYw9I/XjtGPv0KFe1MB5fjdAhnMFVWBG3PNa488Cp4WiQzcibXfAhL+QzM454aFqJUZXjIx8bxGxvjDBouSCFLNP3YvhaD/b5edGDOCNJ0Up/sdvfbsWmHi9JLYTWPegl4OMRpGLtGVolroGtdVmwR7JY80= 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=lfW3rCgW; arc=none smtp.client-ip=209.85.221.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="lfW3rCgW" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-37d43a9bc03so1984109f8f.2 for ; Sat, 26 Oct 2024 05:58:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729947521; x=1730552321; 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=B1pUqif3iHFDI7SYbTlPmHg/+dCSXY6PKzLmSZVOhC8=; b=lfW3rCgW2sgMqUHiRmUaN9Cw/ldPJjnC5fUiEEjzXeBE6HBAgeh1ri80PUBweQnmx6 clKLtRKwpXh20HPKCSC3OsmqO3CGSP0FaRcPy1D5LRLLsCXBqiKQ/eMaxpF6VED1glPT 8xSzc3uY0WS1g66Ng00X6ORgKygUMA3HOD4/r4kxV107ENGboYOqW7dxKH64EtCKjez5 mVFbqIkQdN3f7byOOzq0BntWArbV1gBuw8HooTXXGlbJNDB+RG3+/rmKLkcUK4tqNuGj pbQDOdH20p9Efquqkg262ZNiK0Wdxim+233ii+W5bWOLACD4p8bLTVigDQDgMIJLOyaU vDYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729947521; x=1730552321; 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=B1pUqif3iHFDI7SYbTlPmHg/+dCSXY6PKzLmSZVOhC8=; b=KI+ypWiD/BUD/LtFLDcvgbHL3/OPmRtPZfaYFpAmjAbRa541mFdGUzHN2NEpCO4l3C Jv5SAEVcW/ryCvLf54Z8YQsXuyoWemwhoGNsZpD9CBZVBBH6vziz1Ao4/SR1Dpay7mLW nt63EhBnCg9g8RnqeZzK80N0rZF94iOfCMQLKahIRhOwky8xZ40HKzegcL20EpwLSNa8 xzp7T9fiV856sPD3EN6g7RjQIUd7xOaJw8YLLH/Cwdq9OUFdSv45uvKmHieB/tHAnl5R xCAWDUJtSAX5tR0bjEdNhqutg6yt8unxBtC1Yny1yfV3o+PtBTvjJKhk7eiSx0VKsnvH vM+Q== X-Gm-Message-State: AOJu0YwuPl9nLnUzRdyfqewhRPIKZ76dT0MiHSISP+J8uwKQbuQHmMOt 80li4xmfaRyNPpdItqSR20kg0lCtP/pod3zgZ6SczG94InlbzigWCnB53MBNlXo= X-Google-Smtp-Source: AGHT+IGTg+6KGx1FGlziTjPyikATbdiJCvM2qDMv7s40zqrzR3XQ4ZchoHkb64EQomaYjcPpRt3wPg== X-Received: by 2002:adf:a59a:0:b0:37d:4436:4505 with SMTP id ffacd0b85a97d-38061163da4mr1740072f8f.32.1729947521202; Sat, 26 Oct 2024 05:58:41 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:617b:5770:df34:27]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431935a3edasm47498535e9.22.2024.10.26.05.58.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Oct 2024 05:58:40 -0700 (PDT) From: Bartosz Golaszewski Date: Sat, 26 Oct 2024 14:58:32 +0200 Subject: [PATCH v3 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: <20241026-gpio-notify-sysfs-v3-4-ad8f127d12f5@linaro.org> References: <20241026-gpio-notify-sysfs-v3-0-ad8f127d12f5@linaro.org> In-Reply-To: <20241026-gpio-notify-sysfs-v3-0-ad8f127d12f5@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=DB7XHM1bWYi93YBxo/DVbMZI+iq6kFH/JuWh0KaY6aM=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnHOd6q3I7GmHt2DE30sZZjoAichBXV5wssKUG1 xMsJpkczr+JAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZxznegAKCRARpy6gFHHX cmm3EACyV1KrnkTCo/Oe+9N+xF5qh8UzddSijYG9+/eSIZebmoxYqDRSIJCdPjrnYa73tc8lRMb 6Pfejwzl2s/unY+4ozzgl96yVrpg+lA7zeO2IphpqfU086XCG7x8W3Oj20ajYTKSFXYhjseqVdS m61zwOUePZ21kPZBrk7EoOjgF2GGaPI6it0EEkOj0bseoiBLDWxeQrxLqRjw7TZqdp2h2sI/IVe Qc9qhYp84Cqdn79jNdIyOz3RqDyVZQCGBBihqvLIU9EP82ZF/7f/zGhdbjHdUjoBTFMwZrfLony PodtMRKVcT1G8NyabIN+alVm+Q0L1oZ0a7k7MnJ5V0wwNGNkeOHgItEhYUUw7tHNXktJnx0uPLx hmW7+Xg4895cwBRo0Vst38dCwoU5TMavNB0JHAYT4rQq9bC5ZG71vSxWYbtChPwmHdhsv12M4E2 lsmhsdxs+psfC6lciEo+L8iekBK3H7KqjYdCTo/QDVqX+G5+zytOwWNUZs1bO5mDUN61I/eOkNU ymh5/lcMP8MjOQtDFJP2qYc03lKJNqyoApRE0dS32Gn2/zao63iHrNGa/t5ifk3/UqCELw4NzOo /lZL7B5uEVnGoeGxQ0HdZhtnAgivnfFc1nlHdwBNKaDHQEXkaHhxNuvfcYHczxQjH3M8zxYax9h tBuOwcmlopcl8aw== 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 e1144d3c7645..c0b7f42a0860 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 = gpio_sysfs_request_irq(dev, flags); } + gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG); + return status; } From patchwork Sat Oct 26 12:58:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 838848 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 779641D79A7 for ; Sat, 26 Oct 2024 12:58:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729947525; cv=none; b=jVGzkCXDQcsEeKp1i7FDuIYE9RMQduX7E034N3JgL0zOkLLXe/sahNcin0dN5WEfOpmBEGFQDn71uzcJvxj//jSYGeWVY4nf7+mVZhVMvLBOGD2REbdm3AsOyqP4ilIycxlqzEB3pxXwCRkwApTh+URH/7SWgLI6euMA8F7HLnA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729947525; c=relaxed/simple; bh=bW8qrFgUol+s7+3gDjhkK0B2kD7uN6DwQnNIFUlT4zk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dIqePcXv1W68C7RTSedSa+zhkM3/6zP6cNx/ZcgCBC/M/76QnopFv3+JKa3r7AB/pwpp5cB+OU32drQQjUnQycrsxfI3ijva6YaBwaH6ZW/FYUqhEAzApyYS8FGajlX6Bw/B4BYQ/9k14APFNl9VmcUc4wCA9YTUD/moePycAyc= 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=YGyXXAUM; arc=none smtp.client-ip=209.85.128.54 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="YGyXXAUM" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4314fa33a35so27532865e9.1 for ; Sat, 26 Oct 2024 05:58:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1729947522; x=1730552322; 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=SwfuUsrVXcG/Q5hqvr1hocl/oy9tcRc7ZfbMloqGud4=; b=YGyXXAUMA703mUHu/E021rXEyQho5F06mWqUGYkiNu+F7B3KUzh5jXqyG3m5Kdbbib UzmNmdV/IUcs17DuM9aejYtBrHzbo5hbWZH8mwtLA8ulgSs6tXc+FXgJfO+I3Fzd6JBm lInzV33wMgLMUFcmFOtmeln0Iq3u5cYzQ8N9xcIrGbusV8sbmBEtzXOKclAZYCv4K1es 34IkSaG2RY1aWKHmEyZ7hlPx4gXAKcoY58CwQfuLA40Tt1vnqqBShcBJAp4XfDUopBjE dkidu5tfCsb+Jqtrahq/bB42cvask8SWlNFSHHEZqlnddYXh/lBaZQJbRlCJxR0SQC3Z K3qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729947522; x=1730552322; 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=SwfuUsrVXcG/Q5hqvr1hocl/oy9tcRc7ZfbMloqGud4=; b=A4cowumHovca6Wd8X3d/IdSnW/WcdskbEZLnpxKoW2qlPEqRfph7rCfalS1TmSMtiD U6+gLArJwgPbzhVNjy2gP6AE+9BKJims0Av9kcipCvKQV4BhSTv48l/T/vk3RrjsoYB1 xq9NzlIj+YoGdJPwnCd1eiza/OmVLPg87sUU/HkFumLp5lJUeEzHggn0AtsuqCt+tj8X FlzP9Go44VAr1oCG4AJSUVEvGcaDu5bAxmTkMJJa1SFpObWyu+qwlqVjv33JYj3e36nn 4Sn0KAlUIvVypZ3R3zIW4lzKOkayznHzNmZEa66Z2+bPEc5ZT3NVzh67tZLhamG+EZXP 2T1g== X-Gm-Message-State: AOJu0YzEr5HJEc+e1rOWzxftLRj3AK8tLzkq+p6KWNnVquP0nDvvycgd dMybqt2M/+sXv2bpn8o4ZUUb2OCQhmWWrdnMtaRMlDjWRxdwhaAFeAOxa7FlezI= X-Google-Smtp-Source: AGHT+IFHJsUbQkytNu9WLFPtWbu99lnOz9Ni3qbp2fcQ3uKkMAhzQvRn06v/+K/yJ6xRL1NFmvvZaQ== X-Received: by 2002:a05:600c:4455:b0:42c:b16e:7a22 with SMTP id 5b1f17b1804b1-4319ac9acadmr18410465e9.12.1729947521839; Sat, 26 Oct 2024 05:58:41 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:617b:5770:df34:27]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-431935a3edasm47498535e9.22.2024.10.26.05.58.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Oct 2024 05:58:41 -0700 (PDT) From: Bartosz Golaszewski Date: Sat, 26 Oct 2024 14:58:33 +0200 Subject: [PATCH v3 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: <20241026-gpio-notify-sysfs-v3-5-ad8f127d12f5@linaro.org> References: <20241026-gpio-notify-sysfs-v3-0-ad8f127d12f5@linaro.org> In-Reply-To: <20241026-gpio-notify-sysfs-v3-0-ad8f127d12f5@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=synZM9gyk9YMODwzYkYQGZuMR4c2wQyGyi5f0Leu46g=; b=kA0DAAoBEacuoBRx13IByyZiAGcc53uifGVDUqayr9Nu63c6UYNA6kWe8RXouGvpVqdqTGCW7 4kCMwQAAQoAHRYhBBad62wLw8RgE9LHnxGnLqAUcddyBQJnHOd7AAoJEBGnLqAUcddyVc4P/2Bq 5SHZPBZ3mqTbQcefSCqIjEqNbtA1rb80M3iIJMSx3OcVz+KYqSNHOoeHhobNHW081B6GT24aVtJ tGSdpyB0oDRVP0b11sbyD7AqZpzmtn5TFZ/iOhFgmSRkCmRxfBffX6Akm1verIeaoBvFIsck1sU BBQnuAjhRfp9kMHrpqVPEInXTmTVZ3cW5L7TJad2su6i/+nVFQ6qaZjiscyrANvuFSgawCNrbCs ICg9KDXuNBXpEazuxZAwOKWuylRREoM/wKuQaJhqOsjiOcVCPStEbHOeZMWskecNd7hCRGN5C1E YTpQITO0aIa1faTPkZhxDy2w+zNsgE+j12TfvlpHJfXP9fX/fEcOm+Eazqv4ji+tbMUtucDVpL4 mPTQzvg9CWvZL//R3LkJSV09s+8btdJ4XvPAQsUL/P0S74t6QoJIq4o9CWyFSyiuTn5GjQGNP4G KbFx6pZSI+/rGDMma0NXVHGEeXOZhWASvl3VTvxy/Jc7Ero7C3o+g/Yo5aUlmW5d3Ex87bcx9VM dOIgfrePmZYx1bWy4JIiKDxDRdP7U0gaH5wYEWRJTQqF0Oo7b0PthKXfStFeC7WQ8C3mbgHVt15 O0gwer69CGSwVW/0e/1LDyEz9/4gpLDo6pTFgw9L1SLrJWA8uoMmqqSE4MmClOa83skxj1m0GA5 NYncx 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 c0b7f42a0860..a7aa9fbb226e 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; 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 @@ -210,6 +214,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; @@ -231,6 +237,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); } @@ -282,6 +290,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);