From patchwork Thu Oct 31 20:01: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: 2004857 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=csgL3F1F; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-gpio+bounces-12402-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XfZf00Xbvz1xwc for ; Fri, 1 Nov 2024 07:02:16 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 4E4DF2811E6 for ; Thu, 31 Oct 2024 20:02:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 63A3D1CBE9F; Thu, 31 Oct 2024 20:02:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="csgL3F1F" X-Original-To: linux-gpio@vger.kernel.org Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.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 064C419D899 for ; Thu, 31 Oct 2024 20:02:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730404926; cv=none; b=kvJNmr3vJrPig392BFVNloEJi+l/1U51uqvfXOELC3iXFVYmvjwmge0lsoOTN+QwMa9KzsTBfpDl16IpNvliHt62a1sYxuluS3XpR5xLZ0u+df/InwhKC1PAEYor4H8dBLjyfu0c/h/lASi9dqErhKPpelkUvmotJ34CHSkaE5w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730404926; c=relaxed/simple; bh=3eGsWj3tldB6ErshJTowvNjw6P+DOV6RwonJQjhOJvE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dai0cVM3Bl/vUQ9JX0Jzu9/VoxcXXCPFk4uy0D5G59j9aCvgPIuI8miu2KJGLdiTJedUbjQZ6nLpf71e4jUpMHk5Gtdj/bGUzbrOTnBrBtcfRobyt2g4ovboh/AUfMuAjwyNOJvJkqYa94MnB16SOB+YFUWwEFnmutEuqiJG7EU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=csgL3F1F; arc=none smtp.client-ip=209.85.221.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 Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-37ec4e349f4so810856f8f.0 for ; Thu, 31 Oct 2024 13:02:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1730404922; x=1731009722; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Y6mBZytrDKEzQaEmUgMpFJx27tSq4OYxz5Qwnw3leeA=; b=csgL3F1FFyjMSD/rfYDkQ0WNDyVi7kAkxOYqo6eTVx6+7PQT1oTjzsokHQcB4iEeX4 Zo57jVqbBHGUDvqXKmkhcWXPiMdt536cKXUkiTOeXC1crR7kKTt/6dfX1ie3WzWm3vS+ /YERwsx05YWnsQsr0JqBa4SWariRFsDioOdRID2C3nOlfyoPiwux1ec5BDnAOR4kR1ra dRSmyLXjAYBGuwORnMmSXuRJPb6CqxaRXO8oUZLcZ1aNHe6uLqBiNvr1mTFl6cgMM1Eh AI0TRFIK25iVtYrEixqR3WHms84CW/G/pjq4tCazBosR518A1lSIuYMbg5zbic7+qCuB 1M6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730404922; x=1731009722; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y6mBZytrDKEzQaEmUgMpFJx27tSq4OYxz5Qwnw3leeA=; b=kphoC5beQw7hcXit2dr7L8NDHx5YEtFyn+lD0WARfmgXRDoHZZYNL7CVpFBryhjoC6 gBV37EtN8TVwOWVjAGw4NLlu+iaO5yST9cTVmzypVuWgYE7EzzbrDoGxcgCl2hJ058wC 5eYSbneBdH63H6C7zIuEdWL14jY2SP+aChxiehKPJk67CcByC2wV20z4Cqufyem91emE PYnhD/SryD3EaOV49b9d4VlDNnzl5dK1MkFFFP2yh30ucLcX+dY/PcCKLUTP05EJiD9Y T7gXXC/Lz584k0fuug/FjNhbYQMgLniHjleWBcX8b6eO2CeGUVUhoYSxYMkq1uwc5hgp HCfg== X-Gm-Message-State: AOJu0YzVSGRO73d5EdoXYYpV2gIJWUs9u9lU/WqCkT3mRwyl4mpHc1kE 44dC+rwc2IG0W5/Xnp0UMrxSbIBwubia2aQCFVYJs1j6yFufVFF7wJspx0kQ838= X-Google-Smtp-Source: AGHT+IGAZj09jlUVqaVWH2c9zCPhNV/xPpwAFq1+xmwxeDkiFGYkJBU61+Cwv42I1Tc9EE4zbt3vqA== X-Received: by 2002:a5d:6c63:0:b0:37d:3973:cb8d with SMTP id ffacd0b85a97d-381c7a5e9d5mr977708f8f.24.1730404922353; Thu, 31 Oct 2024 13:02:02 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:f39e:5519:d578:740]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c1189123sm3003993f8f.115.2024.10.31.13.02.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 13:02:01 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 31 Oct 2024 21:01:51 +0100 Subject: [PATCH v4 1/5] gpio: sysfs: use cleanup guards for gpiod_data::mutex Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241031-gpio-notify-sysfs-v4-1-142021c2195c@linaro.org> References: <20241031-gpio-notify-sysfs-v4-0-142021c2195c@linaro.org> In-Reply-To: <20241031-gpio-notify-sysfs-v4-0-142021c2195c@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=4303; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=JtNYy2XqnFeY+eoUoR6vsJSZlTSzQbTj5jXZS6NTCW8=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnI+I2Pd20JG6ct2Q64CVWKREET3/J/otoQpcx9 i8hzT2hHImJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZyPiNgAKCRARpy6gFHHX cvnQEADGPCnvjn8sKxmXZbnLjy/kg3253RNE4qwGiWrwgF4giPL4rsiGz8l9e5dTq9J8ZEoREp9 r9XjOoVC6ZCx3Zc5mmnYLahVVYle8h2hDTtiy482PuU/nBDAxkDB96ihhAfaQiBtQEFUuc9No7k PJy5kVfs+n6x99lxIxpKEvXBwD3UX4rAF88N77rEOCOcK+OqDrLtlZT7FV1HDtHpswH9B0f8lhJ rUHGDCVXtGd9dWWcJeSw6EWDQtafbIAzeF33B4OCGzz6RKd822/uRaxaEjHKGMtbztQKpsjZreF QD3pUX5+cKoJFBgdBUPyGVwVnEdjQsGRk52FYSuzugcmSeCCbyi+S0Q8ILYxWR3R0DFOFrBEUsY BrSsqUhdQ8EmIz3MnO8gv4bpaOfanbHR+8HeLlNQB641fKgjh4GI2laBJbupSbOVmeMgwkaLbZg OM3/t+zVJVmKS3h58SqukHCpAIIMuYQgSdFV6bQVakJH4gsuHL9oWOn8550uEB2dxWqjqnYx392 1UPHGZP/VUYUrIfbvmV0eHAQ5ffThHf2iVE/ZZTVLSD3O7u4KZqDf7JuzuZ2n271hUr3xNj99Sr BE4YgiHF50xyzlc+mTHDYQPgwxTRl9AQBFn4ZRU55riHsVYoIu+ik0OMhhl2ZWPVL5Mw6HIA9lE QXhFjVEMn6Cz5KA== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski Shrink the code and drop some goto labels by using lock guards around gpiod_data::mutex. Signed-off-by: Bartosz Golaszewski --- 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 Thu Oct 31 20:01: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: 2004858 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=A1vdRIA/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-gpio+bounces-12403-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XfZfD13h6z1xwc for ; Fri, 1 Nov 2024 07:02:28 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C42C01F22986 for ; Thu, 31 Oct 2024 20:02:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B0AEB1CC89A; Thu, 31 Oct 2024 20:02:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="A1vdRIA/" X-Original-To: linux-gpio@vger.kernel.org Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C5041C7B62 for ; Thu, 31 Oct 2024 20:02:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730404927; cv=none; b=ZgVcMbxAF8f6Rg2YbqWcQ/xz+GmBWg3ynpmRsaLzE62Fi7buChYoHUYlkkC26KokHr81tHvj7ds0QpiCK8FT77K/CENHBxW46JSp/vA7JG0sXwHyg+T6UxE85Jc1bBZGrTJk4S1tDf3EJlUy62uiFqlbajaYDyWokEZW8dYxolQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730404927; c=relaxed/simple; bh=lxfcHFlINBm4B273RJGWT9N7EfQtgO45pd+YAFioyAU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=chD+gVKStXQB2m1WncjdOFLPIoTZ0yG3B8cB1JqBQdFI/160wr+bfKwHpqUKdAEcu8uu6/h7j1ZQ70SnwyrEkiv72V7PgKUQUEh805HLz+v0z03uV/uhgT3G19ynLz5g0SRTHKFfa2xi3Ct+koN7FKOuvvjrfG3Ly/U1VRU9oQY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=A1vdRIA/; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-37d6ff1cbe1so939902f8f.3 for ; Thu, 31 Oct 2024 13:02:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1730404923; x=1731009723; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=yzrxfr7wPhfTvrfVJLIuoZ9JjJdY5AB7ATojPjTFoR4=; b=A1vdRIA/j6CFHA585KI3akgUqOsi94+PdSdv9J0zO10hiDR2DX0XI4dljLleAgg9Nr X4PGJwG+YZk2aht6+NFEjLFE0poCcIkv2ApIejkVUUwP8P8cp1xyK5viAF7OUHIP0LBm JGayKPkwKHeyy666jM9WwzAOOXO3p7xK/dXk8f/MMTTqV9g43H9tJjnc+TRF9wd2l3+b IuVDgmtM960x98VBn45t3Obg7eFZ0tRACBoYvS1ePGDZvhc3ZkwPCxF8uKbro1EZC7G3 aQPawEFtEqPHUBksukHt5KpbN2QwJHgC6Z8TCHlF5dVduZADBToPmTq5RD9sbrzIt6WM u1NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730404923; x=1731009723; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yzrxfr7wPhfTvrfVJLIuoZ9JjJdY5AB7ATojPjTFoR4=; b=PJVqtWtTpHYi2yyfdAC0oVFnmp7tOa3Uuymk8Z9LM2H+VkLz7fbBmWARXOr8V0n76B pwk97RqN4EBVlWCgKmWEYZ3qP2R3h+Rhnbj9oRQ95gBRsROsv/TfsJqYmJkYrl+J5lH4 EVfp4UYmOwu0pvSWPmNC1fMWX6ECgv77Ofp61GIeg3oEIvtvNOjxuV7idLdftifVCxMd ejlMJFP57aPgpVALSsw5Mf3JQuZ5g+PLTr6feqQEtx7z52H6NnLwp3YKDNWQXvWlWhll 6vJhT1m9C2P0ymv/Ouo13V50LxjsDDLo+9i2V9l9cWVk0zA1IcpHo6wzYoFdW+XBJHTy Q7QQ== X-Gm-Message-State: AOJu0YyWpDXtF6Qf++LHgalv7B5uKIlcZaQpAq5+2iU7ah0cg2Eg2Ncg TNUxzQMH5JOcP5F5tSFlBfKpWUThzrBBEeDIjXA3Z1Tv6MBBzsn2lAcTVANy2bY= X-Google-Smtp-Source: AGHT+IGgFm4zjZjWhXC7650nVqWNS1PFsWNFmkOgJQXkZXvXD+FgAP7Ug+L614sjMLXKokJuGBunpw== X-Received: by 2002:a5d:5988:0:b0:37d:30e7:3865 with SMTP id ffacd0b85a97d-381be7d63e0mr3768793f8f.34.1730404923552; Thu, 31 Oct 2024 13:02:03 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:f39e:5519:d578:740]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c1189123sm3003993f8f.115.2024.10.31.13.02.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 13:02:02 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 31 Oct 2024 21:01:52 +0100 Subject: [PATCH v4 2/5] gpio: sysfs: use cleanup guards for the sysfs_lock mutex Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241031-gpio-notify-sysfs-v4-2-142021c2195c@linaro.org> References: <20241031-gpio-notify-sysfs-v4-0-142021c2195c@linaro.org> In-Reply-To: <20241031-gpio-notify-sysfs-v4-0-142021c2195c@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2976; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=hQbFwd1QT9qA/6G04ep+yw6mU1491E7zvhbWfpDUDoM=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnI+I2RfXIbXJmBgVj3RdDRuu1VHrPbMrDmhip1 i4/Nv5KCieJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZyPiNgAKCRARpy6gFHHX cuR0EADJxy3vXb63V7EH/zHNUnjvJN4b/Jnp/CIAd6WwUskF72NdGGNHTRQzMXEMvcgewrEk2hR 14WOrVchK+ryfS85FkruV8qf94ButgWv0rjh7tf8DvkI+kqQD69+tC70yTCZ4pHOte0Z5zEc2JB PNXUjSFL9RhoeBXWPE4ZsprN5UmtRx9XrNjCCKolq1PrDaGeBnZYrF9DYcGf00hrpTwufg1CbRH mSJ5PnXmCOzGbVVP5J/4dZ4M8RgXYDHr67ZRUAkwRWvginLBwNA5ZZCDKl+LRWbXeSxdhO9uK4C F3Vgeu2H1LBBD96tIzyGVu+rwFlnl+rYBk1Z4xIph6tyfa5vgFfaoMaxBLfKcrZVKj+OHdOZpvl /znYWNXA26/7FinsE5rwGOfKlgJ4NFYrtzsds98qre84LJUw8ZDKwDdaayU7jPP+9siATW0hu4Q jPBJuanaliUmNcxiJNeBvpxqHn2VEs3z+44kvOx/qYZoHg/os6TWE7Un1hKvQorNldyIqZqhHpK 0uW6Q8yuREGLdr4ez609UwHl8Z9XY2BK6oafvDoN1aay7an4wYP1ex8WBvHoy9zge+nlppY8E9G ZA/J09WyVgumZ5XgKYXsyczyHTyAbOePwFViM0D0iEHNWmRQieoyiOAV843wD3yLDfyVnN5cvQZ fK96CAgt4iPXWDQ== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski Shrink the code and remove some goto labels by using guards around the sysfs_lock mutex. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-sysfs.c | 55 ++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index a0926a1061ae..e6c1e26f302d 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -575,24 +575,24 @@ int gpiod_export(struct gpio_desc *desc, bool 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); if (!data) { status = -ENOMEM; - goto err_unlock; + goto err_clear_bit; } data->desc = desc; @@ -610,13 +610,11 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change) goto err_free_data; } - mutex_unlock(&sysfs_lock); 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 +678,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 +740,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 Thu Oct 31 20:01: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: 2004859 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=XPNgh9c7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-gpio+bounces-12404-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XfZfR6LSJz1xwc for ; Fri, 1 Nov 2024 07:02:39 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A13EF1F2295B for ; Thu, 31 Oct 2024 20:02:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E41321CCEDA; Thu, 31 Oct 2024 20:02:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="XPNgh9c7" X-Original-To: linux-gpio@vger.kernel.org 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 B01D01CBEBE for ; Thu, 31 Oct 2024 20:02:06 +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=1730404928; cv=none; b=MjuVkyHe1qyboXFWJ+WqMQz+DEIlRkjLa5kE8BeHakh2Ro8EKPgRAFRJ7J6AR3FCVODkECI5U4PSONalcJVeHXb6vtRmvj9zjJR9drHjHzb6QfMRMur3zo7VXoO5JqIe6J+2LlpS+vCnYtijbWGhhuPmMUYKXPnnmELIYD2yTlM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730404928; c=relaxed/simple; bh=32n8hNRrxZfRWXJHlXEUvVQAOaKpzejZ0VhlHU1F83o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pBs5l7V9lzYlLnpl7rWwsk/WXoMLMi5aWL68w56WBvoANoE7bIuOBDi7tp7Mj09dpo4q5Uf6XCfPzy1MhprtLDSNxN2bvyh1KIZt3A+lPhIiXUh77wSWWywmnD1dDrzWu6NIBLGFvNIzGlGN46lxyZ5YYyQzT2BkbYWwqaD2scM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=XPNgh9c7; arc=none smtp.client-ip=209.85.128.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 Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4314b316495so11563885e9.2 for ; Thu, 31 Oct 2024 13:02:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1730404925; x=1731009725; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=1gPEduXI+XMe6Dm5bWiV+D66hZVETOkYyz3aI9yIIqU=; b=XPNgh9c7MtaX1g3kZDeksVVYRM8FpqFLJiLZYh++w/ClY/h4JkTdK+66VUzZATypez vLel5IHtuDM4pZKzYsITbHGhLHqASsI/FfRqkb3+hDzPpVUjuclYvdPYmcZOFWlmENS/ 4aJ3E4VB42QJi1sFCNmztHwFoYFGFUNeXL9d/1PkpAjHTJHsJYmJgUmVBxFSv4SnmQc7 XW13jNTZ3dGHbzns1IPzX0bUXK14N8VAafrfauOFuGDEr8SXirYusaugjTrbPkauHFN+ ltv9Qi7GJmvuVB77OzzyvywT3Xzi0UTE8J3P1hxfKylPBBdSvQKHhnL9FrUlBQfz4spF hXdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730404925; x=1731009725; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1gPEduXI+XMe6Dm5bWiV+D66hZVETOkYyz3aI9yIIqU=; b=VQGv5hFlzd5ow6jgEM0aTJ5ZgCjcJaI3frNNVldWDfASTwBmR6e028r4JdkqPER6Ci 55yxLYarl7loaPAZMvdkp9hRgcTEDZzz+/x5zYznqaZZdUYa+LUrqUB/TMFoHD1Yq5B+ ZAywrqsxV78NIS1f0QnsvMKSsm5e09al1FUNgcc6zVPILnWwYHbMbimMmFfmPvtdbZgk QFw/jJTWzKpwDed6/uxlhGE9E5LJXjxBNQT5dadtPMMlWnyMryPpjq1JfxhNyhq6JL33 Lt2fb+vbSAwY4/dggBSOHf6hAoXsYvwl4Ez6+thQ+tm4+cZNqumrTAKrtrVUY+AkBcUH zQ6Q== X-Gm-Message-State: AOJu0YyuZ4XThV9xErfbhb2TopFg4rt5QtvVW/tiSkx7UV1GGjb0pDan T23mlCTdDdrRDPmXGQULf8xYyOfFpuX1vUWQ7OiF11WUfKUl+iDE+5Y99p6MB+M= X-Google-Smtp-Source: AGHT+IGBYSgTZbJrlfDKZLP7kcrkgkxX/vih99iJkm8GYhF8BuKcQzph7Yrmgl8WnNkSLt5YSmea7g== X-Received: by 2002:a5d:6d05:0:b0:37d:4cd5:fff2 with SMTP id ffacd0b85a97d-381be764d8fmr3245266f8f.6.1730404924872; Thu, 31 Oct 2024 13:02:04 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:f39e:5519:d578:740]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c1189123sm3003993f8f.115.2024.10.31.13.02.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 13:02:04 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 31 Oct 2024 21:01:53 +0100 Subject: [PATCH v4 3/5] gpio: sysfs: emit chardev line-state events on GPIO export Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241031-gpio-notify-sysfs-v4-3-142021c2195c@linaro.org> References: <20241031-gpio-notify-sysfs-v4-0-142021c2195c@linaro.org> In-Reply-To: <20241031-gpio-notify-sysfs-v4-0-142021c2195c@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1117; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=MW68g60TEyuTeEqNXNwM1N7WdnOvX+cyTXG9bH58n2A=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnI+I3m8f03GVVwHU8kH4TDVsfKfCXZsPvSgUIR qUK4XATNYyJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZyPiNwAKCRARpy6gFHHX ctjGD/4uCWXLERvN+D9onG6oz17et5OWI9Qcnc255pX6RAb1J7TPgAeTUDIO/BYJ9tVvuTChhq/ Y3qyL7lerbZGw38TFPZufpRrinZvYhM2KOfgaMcuEf7PEMTMSVJCXIrZSwamMROCPhh56Ci67Kl DjKloeKVrPXJbx5OZ9dFME+JTsoGQx03uImflSuS+LQi/CcOw/wYBSnBMIBNrN9YPXfmfBYX+zJ 3+4ALAHwOLIHLsanzSJUAA3/xYkWxjtkWym+zhOjpkVeJwB2aWDubirBbKJpJm+uyIaJZ/lkrXN S6OEK7xonnipE29S+2MznQPRld2nME6bR+ZkcSI54usUybTMdUiMro1OnVOqSqRbfO1sYTOMepf Evz8ZcJ2LY8jVpBEY2bnCgavoSljHhTx815mhZuAFDfwKAy4SX2V3ct2INqXLOk1eQOPpPGuW4f N4hKoD8r7g3Dqi/uvyC60c/vCZXb8evhaqfiSyQAHJdNQGsA4OlJZKhEHFzAIMd3sGPvr6FCc5Z ipAt8LOqEkewZwWjb0XJI5acG2HPRtXS8+PepjXTkNl9HO9MGO0/IjTYMrK0gGYkYmDbXiPzSzp 5ONHqGgglXJtBLFRxnBl20eFkTAA1ypuxqC2PepBQ3c6wwrJezYLJ/Rp2Af4DBUgRcgg2zd5zre JcDzYtimkq2LtNA== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski We already emit a CONFIG_RELEASED event when a line is unexported over sysfs (this is handled by gpiod_free()) but we don't do the opposite when it's exported. This adds the missing call to gpiod_line_state_notify(). Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-sysfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index e6c1e26f302d..dd5e850c9517 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -21,6 +21,8 @@ #include #include +#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 Thu Oct 31 20:01: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: 2004860 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=b2hH9/9b; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-gpio+bounces-12405-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XfZfd3CKvz1xwc for ; Fri, 1 Nov 2024 07:02:49 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id BFDFE282CB3 for ; Thu, 31 Oct 2024 20:02:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 082241CDA39; Thu, 31 Oct 2024 20:02:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="b2hH9/9b" X-Original-To: linux-gpio@vger.kernel.org Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CFDFF1C7B62 for ; Thu, 31 Oct 2024 20:02:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730404929; cv=none; b=g8GSFDbgrFoZMPW7GldJuzmcVB0LjZPCBAT0Vw7CLq8egewoICsj5Sj4irQQV80kZaIc5ZfU6OivOyzzh1U8VBbrMss9tzk9EIsY05zwSZ27+JES87CVQRKyys5OhNn7HqQdeqK5gPkMfilysoicxOfS9yv0Njx/Vq4TgLg3A/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730404929; c=relaxed/simple; bh=LYpUIS6TNygS1bs1G3bDT7Wvnqt3+q3GyXXZY5PUn8s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OtAL/LdRgUwvi8BxQv92XtpqgsQE1vvvpiOyGv3iT/cHyEuaJcWcxEEtX49mTGA+OkCUaphUWcbUAAL/Jgm73Qps4NDrVR/+jCjje12BTL26FTFTlCPgiKP/PWEUfov1QFnhXxfUI+sDMnI/W5W55ZcLX6l6mE3RyJrSu7n7hEA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=b2hH9/9b; arc=none smtp.client-ip=209.85.221.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-37d49ffaba6so896204f8f.0 for ; Thu, 31 Oct 2024 13:02:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1730404926; x=1731009726; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=S3+/PTENuc0Wqcd74grjNgAYyt4poP34aWyssLFyctE=; b=b2hH9/9bHcttljhh90MZfSQiZ32uxpV/1/zMXjivir3BoeFAKmxnty7jQqm395Pf7Z p7u/uQeaO8gxPx5TGo2d1CfegKJJhwgUVfEc+1LK0HKERE4rXQ+UFPejni8aAmVVrF5S HjWl+2RJ0F8fdTwL8Cy2uNi6JueGnFC6bJKoqQmavyyGHW92M/ASGWQXDUmmHmnl3lP1 USuhnQnL5ZjC5hyg4mh3be0DQTvpGFv0VwlctD7Hx0J4jzO/0R90+w14y0muIefDHpRA ELBeEuzDstZAwXwQLudi8+Nz33B30zMElnzUHu5FJQ0eukFS2i8PxkvaER1sQgO5cxy4 q2aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730404926; x=1731009726; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S3+/PTENuc0Wqcd74grjNgAYyt4poP34aWyssLFyctE=; b=gtifWx7RM83HGFNxHcIl/X519Y4pUvfnEm4impTi9GV5fte2/ZQR6q3FTv0YgrwSlz qRa31HCCMuuTM6v0wBlLyIBKlnRrnhoz8jJM9p+aV28t9FUy+1GdrqWnM2MQbtlK7epq o67D+4Z3+8eJ0TTDMR5zCx3iYVWqPBuW2GZOliwcThVFUTNmA3FSR4wtNX1XakUFccms /UMsW22BVtxPVUEh0muv2PcgSUF0HGfoITcEgY296Vy1lU5SyLCW6HddlSSigflO4VaX UFnPydPGF4RPL3QUx0NiZR7M5B+qRDSujKVO3ukBoo/LqZlBNk8YlCFePZoptYsyh9+z 2OTg== X-Gm-Message-State: AOJu0YwXxpQMh+5gRG0ZqL6h1AAGUlz42Xex0xPNPOaF8RIue5Q8Rqod DoHeJy0Dw3YAgI1Ow4N5Wzuatopo2YG8PnYdYrGD+ymIIILSuZzXURtvqbTY4Yg= X-Google-Smtp-Source: AGHT+IEmggNr+FEuZkXM1x0nNEKjGuUO++8XIqYVMGPsMqKP5Nv3ooR/+gyU7rfS3q5Ho1x6/Ve5EA== X-Received: by 2002:a5d:5482:0:b0:37c:d179:2f73 with SMTP id ffacd0b85a97d-381b70750d9mr5695759f8f.13.1730404926198; Thu, 31 Oct 2024 13:02:06 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:f39e:5519:d578:740]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c1189123sm3003993f8f.115.2024.10.31.13.02.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 13:02:05 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 31 Oct 2024 21:01:54 +0100 Subject: [PATCH v4 4/5] gpio: sysfs: emit chardev line-state events on active-low changes Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241031-gpio-notify-sysfs-v4-4-142021c2195c@linaro.org> References: <20241031-gpio-notify-sysfs-v4-0-142021c2195c@linaro.org> In-Reply-To: <20241031-gpio-notify-sysfs-v4-0-142021c2195c@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=781; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=ddPywcbmdK3xi5YOlUy1LjF/4WaHOEFU26L5BClPYq4=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnI+I3uiyYeJL4xbj/FYYWRgfQkObIqepxhrze8 C3IRb8mG2CJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZyPiNwAKCRARpy6gFHHX coElEACfsl0RNSaWVN1L4qPsEc6stxgG0y8cHF0NAGIWQF9vV42tAA0R2333wH5PCcOyHrOLiNi wdq4VWH67fJc+0cuD03CGjCuvzbxhTVJVoOfmBq6bz2s0yhrQhv+ECLW7EUQpKRudSSdsTRQYTQ 4ysRMJasmvSovf4dJzg3dQhTmseA7/DkfKO9p5kV/JbG0py8zNC7F4Irh6EzfUnUD43g/xuEGHh PU2xcWRaB778XYg2kVqwaQDGNNlZivAuY739UJEOEQ9Y9jovRCVmlrwegJCDKmIXYsJ9LS9f4DT 8+uUv/Ivr0Fim/I0uyri2ho+0cRFhn1tg8pWE69ff9mzAWvgr0BLHfoEjp1Y5VAeLVI4+iaOQbB sxs4c+EUNJkwD6eVrK3UDeTlqilbIOmdyW3AgEYxLyn3wiU+YO1bFxE04PwDot5xThs63u9Zan4 CWymhAUd9onDw+s2/IQDLKSU0NOx5C44mCg3hjTwnP0T56pcpJG5lZ9wmI1ra79Mj5Vu7dPpz+1 8kF4CsQJF62JKTmCie1i+afVjyAewuV+KGF8P4Rsvihu2d3etJFdYcVG0QUiMRr0ItuOqwt+Qvw x/VlDxmwS1b24B7zZFqh8TDE75T+lhVdU2i06rs6YF9DMzcwSzfFpmH1DG5pbBWq3pFGFGW/Rfu uAd7jsFyy03dTuA== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski The sysfs active_low attribute doesn't go through the usual paths so it doesn't emit the line-state event. Add the missing call to gpiod_line_state_notify() to gpio_sysfs_set_active_low(). Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-sysfs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index dd5e850c9517..49a5aa89cafc 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -307,6 +307,8 @@ static int gpio_sysfs_set_active_low(struct device *dev, int value) status = gpio_sysfs_request_irq(dev, flags); } + gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG); + return status; } From patchwork Thu Oct 31 20:01: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: 2004861 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=KukWMSYm; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.80.249; helo=am.mirrors.kernel.org; envelope-from=linux-gpio+bounces-12406-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [147.75.80.249]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XfZg13ZjBz1xwc for ; Fri, 1 Nov 2024 07:03:09 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id EB7161F231D4 for ; Thu, 31 Oct 2024 20:03:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A16C21CEADC; Thu, 31 Oct 2024 20:02:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="KukWMSYm" X-Original-To: linux-gpio@vger.kernel.org Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B0BD1CCEF1 for ; Thu, 31 Oct 2024 20:02:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730404931; cv=none; b=cqBwdoH5RLNDrHaem1QpF5Mi8dchWAvpOQscqlAId4dChNlYfJj0yjGddvXySBzH445T13e01Tr4YKe2SQd8Cjn9AVRpQbWnaU7WOHkmfJv/NO1WDVmkHzeXHc20u79ASddGkAsu7AuEiHfmS5WHXRS7fHDKTFNJd5ASjSd+t6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730404931; c=relaxed/simple; bh=grXFaneMr1ISdxB6vm0ixLnCulIRiajDw5Hs4ZGd2QI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=p30kw5J6vpYOqz9UKPuVEs11igy9z2wV5J7uy5sxeBSkbwTsCHqCq/h2IvW1iv7wVr7RqEmdq8WPYMzWQZW8Vhsj6stfiDse8JmwPFly3cM3LZvkVuf/SoNL9VdafZ00ZJZy8jNlGAKMHm3rGFXQmns0vTpgjRoE/sLoGC9vgkE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=KukWMSYm; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4315e9e9642so11723835e9.0 for ; Thu, 31 Oct 2024 13:02:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1730404928; x=1731009728; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=HG0t4NeqbVLn85G3sOjEZke50iDELODkv6ssAwuGw0k=; b=KukWMSYmZAP0rQRob9dCMV93pkgneMVxONCqrE3ElMEVOCe0Oyl4YnCVYc7iLw4Ho7 KzJHTBznIQr2yhKI+F3iohjJnXM6YcXeUbfRbZra7jdYbxhcICd1c/QRA2fu6DLhxnDI IKS2SspLtmzE5PVE2Aj6fOk/N5zbHMcNqLXvkqY9kMy2uhTdNUgCVmTKd+Fe8BNf510d DKIjTuVxdbrNQ9OxV4kvESKM+KgYyd9iYzIjVQ9uu45kleEPBsGunm2mzePVrc2A+hut drQsmii/J2ECn9JcFuzRw5b4TD8E9RBLkTjZxPoWkHwIFvxc1EU4wlUjpJ73G+m7/wlB eR6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730404928; x=1731009728; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HG0t4NeqbVLn85G3sOjEZke50iDELODkv6ssAwuGw0k=; b=cKfK28dYr+P4MDnmPBm/wxMwILHkXl0O1rlnx3WrMxwNapLC8LA6/lFezn2OSMTmCZ dsXw4AjbYdeK0qOJJ0Jo74edy0h+CF/ea6Nn9pdUNZq3/jBkepAWNFvhZi9wYIXPdeha nqHfJeF1Z90fBzsPcddPmn0+TFVICKG4VfyKfYYsAY90tKumJLjV+w/qPnyExtajkroM avMXmeUlW4Bloq7frPeie8ZNK9rKggZX1RtSLZpsbzZomGAXMz9sJacA1zDpLJUD4dVU CRjM5W8tIEeTRd1Xi2izAGLZN9ZT0k/NubkFdZfRVWskrbGXc16v1aqG9xeg7hDPsPLQ NKYQ== X-Gm-Message-State: AOJu0YyLQDFLd6oKZDlopJd8IZqiee2/jghY5E7oHwuQfTWg0HpjQ8v/ ssxtsCr0UnbzzDExg7uSDRO1WWC5+3G8SeBPkbVtrMUWLUcDr00hsPJuSbig4tk= X-Google-Smtp-Source: AGHT+IFdJz3U9m7KPLf0+/MvSmAS4Ua279P5RD6u7ZsSqyiraKix7E62FxZs6WZVT7OQXDxf0bMwtw== X-Received: by 2002:a5d:64e7:0:b0:37d:49cc:cadc with SMTP id ffacd0b85a97d-381be7c20ebmr3290683f8f.32.1730404927612; Thu, 31 Oct 2024 13:02:07 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:f39e:5519:d578:740]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c1189123sm3003993f8f.115.2024.10.31.13.02.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 13:02:06 -0700 (PDT) From: Bartosz Golaszewski Date: Thu, 31 Oct 2024 21:01:55 +0100 Subject: [PATCH v4 5/5] gpio: sysfs: emit chardev line-state events on edge store Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241031-gpio-notify-sysfs-v4-5-142021c2195c@linaro.org> References: <20241031-gpio-notify-sysfs-v4-0-142021c2195c@linaro.org> In-Reply-To: <20241031-gpio-notify-sysfs-v4-0-142021c2195c@linaro.org> To: Linus Walleij , Bartosz Golaszewski , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2143; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=VPwlZ8nGOi8NK4NOOYE429uUxxX6CyDyQfdMC7P82fI=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBnI+I4WmYgaN7hopWfPfyg4/7kgpmKSho8uMiuI hmLg4nTrsuJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZyPiOAAKCRARpy6gFHHX chfJD/9xX94dUejypKQ2wDpArGCpy1bvkeHW93n1gGrPEIHITENtbuA7vJ/bVDI8pTXHocA6WuK oPPppHXRoqSZT2iV5Gx+CjftykF/fnHH0r8ICbZKa9hZ1vzB33XSlbAgLTR7/KZJLO+sZ0hMGzP ZiCAxXRpoR4a0x3JBkDMEiRqWUwXNcHkOeZBWNZTPfDV0KacyVWpBadl//yWM+c2QZwVYAFt3Fj YzWrZXNUNRlXHxXb4j7KxNOTx/xaaIulu9hHBOZWkz9hjNY+9EwocM4U5pUj8FzdgMKJd5VEa+o KtS44V4S+OjYJsHTFuNmmMzQnUhUrfZTee5LYCWTjn3A/K3wkq2lV4VGpC/3zA2+xI+eG3JbdGq cQP1DMVdS0f6pZX924SbP6fYGbnLqaKA2T+a5uzD/AZxpXjxu7SnAyEnbxKAwAqHB+Ufk7uzP5g NhhvZr9Wcx7CXy31GsztEf5J6GqGxkWhZUkeUvMRZ9QvzEkvHvoMj/qsUmNGVo91KUB+6ZMl3Ro CAOTOvIqnMhB14UAK4nCLlFSYQdKt9PZ47ztVNhfujHTNkcLYqfHQZuRBzVjeUR6/5gAkepdIlu 7pGKaVcfSK9+h0/HUniQQBgtIOovr2R9t9aJVjU3xt1XL0abW9tfJHt5nnGrJXMZqhHcz7CUvgm Y4G1BDstItyFFDg== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski In order to emit line-state events on edge changes in sysfs, update the EDGE flags in the descriptor in gpio_sysfs_request_irq() and emit the event on a successful store. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-sysfs.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 49a5aa89cafc..5d7e8e64783c 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -179,12 +179,16 @@ static int gpio_sysfs_request_irq(struct device *dev, unsigned char flags) return -ENODEV; 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);