From patchwork Thu Nov 30 13:46:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 749601 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="rAgWJ7wy" Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4273C171E for ; Thu, 30 Nov 2023 05:46:38 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3331974c2d2so683959f8f.2 for ; Thu, 30 Nov 2023 05:46:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701351997; x=1701956797; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=W2vlGJhIze8sK7FhkyHeBLiiHYWZ044RLoNjc90UYtQ=; b=rAgWJ7wyrL/2May5aYimych21ZT2tm9IZy5+6tzsEA7vOXntL9Srb5PvQQ9TcF6NhF MaEOY5BLqtebCj71nnSZ6qxpL+an6GBNQd5/zmkU+Jvd2/5lH1DjGPS8/iFLmCBKwIQj 3eyEZNgYmlJ/AsdyLG2EdoK0emymKfJNylO6MyjoYvqAVqCmw/jR4ovjxSQ5Zgzhz3IV e5+kOKCKXTGWmBja+iAksyYMosvX3FgCmT+cLnsvxTc8mZ2ePWnIZFPDLR5etuIvNaF5 XQFvEU7OZHF/bknywPNNwqgMz7tECkqqyusch/F0ivM1MruvTvbMlKblV6nA8drVsEeJ VUsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701351997; x=1701956797; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W2vlGJhIze8sK7FhkyHeBLiiHYWZ044RLoNjc90UYtQ=; b=DxAT2bMvMMCtTwdqL3U6xOZcqTHjWcgpSil+KtvSfrZ8WAq8Uw3/a+YlW1RSBJyDVJ 04xwsRnKuGPvot52IIi0cLX40GTwFu5wyKdxVeRqxe5ECll35Rx/SK6x8r4plHBjL/M2 opH41ycNDjGpW1OLkCE5SZAW+FPeedU5Tsi5iNoR3z4zssPP6JXgvSGTvdarztp0s9NJ XOG4gNUUZiQX1/iumkMSBRnrIyEgEOzUIxTdaOC8NODFpsm2oiRTiM5Kp7W+V3ZxHfKe xpkTIg48ZRbMqicErKdLpwh2K0RmIqFay/yL+eynPbVUxvk1GnnNvxf99K27kSLO+tMj I6kg== X-Gm-Message-State: AOJu0YwxbU2QZpy8HUaA4HKNyiPzdjrmPJeNgC0yqXQnmoQrxRx0S/PG pu/ZL4rEb0AFPrPxwjuXZBAUJQ== X-Google-Smtp-Source: AGHT+IGtdd0VMXL+p2c6eyqLy6MItc8V4wcu+0Ncauj4wLWwBbw5ot6jZfezOIhzkjhPuljZoeg+Vg== X-Received: by 2002:adf:f64a:0:b0:333:12f9:d37a with SMTP id x10-20020adff64a000000b0033312f9d37amr5219213wrp.65.1701351996563; Thu, 30 Nov 2023 05:46:36 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:ae84:904:6602:ec1e]) by smtp.gmail.com with ESMTPSA id n18-20020adffe12000000b0032d2489a399sm1574824wrr.49.2023.11.30.05.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 05:46:35 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 01/10] gpiolib: provide gpiochip_dup_line_label() Date: Thu, 30 Nov 2023 14:46:21 +0100 Message-Id: <20231130134630.18198-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231130134630.18198-1-brgl@bgdev.pl> References: <20231130134630.18198-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bartosz Golaszewski gpiochip_is_requested() not only has a misleading name but it returns a pointer to a string that is freed when the descriptor is released. Provide a new helper meant to replace it, which returns a copy of the label string instead. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 29 +++++++++++++++++++++++++++++ include/linux/gpio/driver.h | 1 + 2 files changed, 30 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index a5faaea6915d..8e932e6a6a8d 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2400,6 +2400,35 @@ const char *gpiochip_is_requested(struct gpio_chip *gc, unsigned int offset) } EXPORT_SYMBOL_GPL(gpiochip_is_requested); +/** + * gpiochip_dup_line_label - Get a copy of the consumer label. + * @gc: GPIO chip controlling this line. + * @offset: Hardware offset of the line. + * + * Returns: + * Pointer to a copy of the consumer label if the line is requested or NULL + * if it's not. If a valid pointer was returned, it must be freed using + * kfree(). In case of a memory allocation error, the function returns %ENOMEM. + * + * Must not be called from atomic context. + */ +char *gpiochip_dup_line_label(struct gpio_chip *gc, unsigned int offset) +{ + const char *label; + char *cpy; + + label = gpiochip_is_requested(gc, offset); + if (!label) + return NULL; + + cpy = kstrdup(label, GFP_KERNEL); + if (!cpy) + return ERR_PTR(-ENOMEM); + + return cpy; +} +EXPORT_SYMBOL_GPL(gpiochip_dup_line_label); + /** * gpiochip_request_own_desc - Allow GPIO chip to request its own descriptor * @gc: GPIO chip diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 100c329dc986..9796a34e2fee 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -532,6 +532,7 @@ struct gpio_chip { }; const char *gpiochip_is_requested(struct gpio_chip *gc, unsigned int offset); +char *gpiochip_dup_line_label(struct gpio_chip *gc, unsigned int offset); /** * for_each_requested_gpio_in_range - iterates over requested GPIOs in a given range From patchwork Thu Nov 30 13:46:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 748827 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="RzoE4DJW" Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50F9C1724 for ; Thu, 30 Nov 2023 05:46:39 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-332d5c852a0so550802f8f.3 for ; Thu, 30 Nov 2023 05:46:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701351998; x=1701956798; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5Sv99NjQCF32QfqStrxQNV++EDXzWOND44xPhDEPFwA=; b=RzoE4DJWVF3W3nkJlOJRdv4+NmcgoXiLB+gg1BmbJAdSjXdO6QHD0KtdwJ+12Fl3My 55WXpqcLmbIhqfB6EXiyC3TOB4t4821ZMjkrX2BgMv+g/RKT0pGNt4btfGBlA661c49i FWG4egQtdxheJcTMecL/3iHGJ2F1A1sf55X5HMWQdtzYxnvUyZNHOhC6YeX1Oq//Y8H5 xAEmCuCmY6y/ndwSGq8O4w9WCzjyLssVqySoFOm4Hw/o6elLOYT3mx5hy9+t3+IkLrWJ 0jtXDfm3avWCkFD/JE6oXDJz91f74VpKSPmW8XzyKygh1SgtzXazFW4CeZw+rW9VmLlA HcYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701351998; x=1701956798; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5Sv99NjQCF32QfqStrxQNV++EDXzWOND44xPhDEPFwA=; b=eq//wHUTmEQB5NUAbhVG4V6U9Cu9eb8xdP4/fcMc3RSX3QsUBS55tfvmP1g9XsohbT l28/nPNR6s1qzzp8iSiUyutylJvL/675Gx8bRe7inciNsI369PmirqBduT38Kz4owP6g ADm0rwn/2DaIxl+ZQmxWZokE6bA+XnNbnTYfw2Lu1q39tfWhxIE2IcSZTB3a4b/wiUAa 5PwUicDYI0ciAE5WHf/Jsmys9KMHqnLaljC1Dr7HUulgDMRWA5PV83oqHH65kFa6manU lN0phfnjpvc6fv47j+2m51NgsPw53UJZwFfzC15F9IvbtDxpqf/9V5EzYXU6JA2c3OgW E4Zw== X-Gm-Message-State: AOJu0Yy4uX4AOjvKqTG98GqnSa8qhxfL0Yf3RboL4Dpz30cXxxNC3fq9 nNeH/ceoReorgG4gMRTEvpJTJx3IZrfFMu7Mk3E= X-Google-Smtp-Source: AGHT+IFFXiw8d4gEC87uJuGJeNe0IjCzYDScTUcvPWnXguWxDUdRf/gDmALnF5depRlp+rrGf1ryhQ== X-Received: by 2002:a5d:6dcb:0:b0:332:fcd2:87fa with SMTP id d11-20020a5d6dcb000000b00332fcd287famr8728856wrz.27.1701351997780; Thu, 30 Nov 2023 05:46:37 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:ae84:904:6602:ec1e]) by smtp.gmail.com with ESMTPSA id n18-20020adffe12000000b0032d2489a399sm1574824wrr.49.2023.11.30.05.46.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 05:46:36 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 02/10] gpio: wm831x: use gpiochip_dup_line_label() Date: Thu, 30 Nov 2023 14:46:22 +0100 Message-Id: <20231130134630.18198-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231130134630.18198-1-brgl@bgdev.pl> References: <20231130134630.18198-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bartosz Golaszewski Use the new gpiochip_dup_line_label() helper to safely retrieve the descriptor label. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-wm831x.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/gpio/gpio-wm831x.c b/drivers/gpio/gpio-wm831x.c index 7eaf8a28638c..f7d5120ff8f1 100644 --- a/drivers/gpio/gpio-wm831x.c +++ b/drivers/gpio/gpio-wm831x.c @@ -8,6 +8,7 @@ * */ +#include #include #include #include @@ -160,18 +161,21 @@ static void wm831x_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) for (i = 0; i < chip->ngpio; i++) { int gpio = i + chip->base; int reg; - const char *label, *pull, *powerdomain; + const char *pull, *powerdomain; /* We report the GPIO even if it's not requested since * we're also reporting things like alternate * functions which apply even when the GPIO is not in * use as a GPIO. */ - label = gpiochip_is_requested(chip, i); - if (!label) - label = "Unrequested"; + char *label __free(kfree) = gpiochip_dup_line_label(chip, i); + if (IS_ERR(label)) { + dev_err(wm831x->dev, "Failed to duplicate label\n"); + continue; + } - seq_printf(s, " gpio-%-3d (%-20.20s) ", gpio, label); + seq_printf(s, " gpio-%-3d (%-20.20s) ", + gpio, label ?: "Unrequested"); reg = wm831x_reg_read(wm831x, WM831X_GPIO1_CONTROL + i); if (reg < 0) { From patchwork Thu Nov 30 13:46:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 749600 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="zO8d/RkZ" Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D8911703 for ; Thu, 30 Nov 2023 05:46:40 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40b4c2ef584so7729455e9.3 for ; Thu, 30 Nov 2023 05:46:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701351999; x=1701956799; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FDkm1mz5JKda1Ie70um5gnCumWIdGzqKbagKhi4Mqgw=; b=zO8d/RkZCozzHJ1jQKXdjSYznCbMIc23SHbSreyOKRFdYVhP+l2K2kxpdx5TeawVYM VObqZNzZkS73Kgy2UHewywsdJy3thgug3aq1ahTKAS2Oi61OSGMT8uHiliaZMkCBqGKH c/EkgFyKTTd878s3uk4QQTsN4e9IODJ/PNeZq24BOYkTKTyQYtJQExNUIUiCGvf+2tSo xdavwY5etTRVDax7kAnqhIAWMcrNnOQWIEyv/JuUXmRpPS6qHavUxpja+hqxJqokGvMP rnkdRhh4xz5psfSzzIlgywWJONcSfUzV2v8aoKx4MrWMERKU0/fYnxP8nCNj2vGPnRzF qJIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701351999; x=1701956799; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FDkm1mz5JKda1Ie70um5gnCumWIdGzqKbagKhi4Mqgw=; b=qqmgIb4h1NqPCFC3zUj70ER7iz04TvJ660+Aus7smCDIdeIr9o4VFbvoEk5UbK6v09 nSFr+fx+7r2UK+p8ZUW3Oqm/ICnOCsOxocwhYY8Zs3XyUAnJ4XIidd31A6Y+iUJk2ZyC PqIgFnr7CeMVX7B+Z+OLqhHZ99WMfjYfFGHQ3zOqRKwdHDp85MMcfqP3lijQlYlEE4Rx hACE5Cxzw675wbJil8XDJ7m22347vcUn/LkpEpK9HEnmg17PWeBfovtlb84OG4Hlg1pN 0wuYhQpO1Yy22hP57gjQR6cVvfh0In5R1g6sgm7AcnpyA38YSkYaANM8+GQ3zTyah5s0 hlKw== X-Gm-Message-State: AOJu0YyPqO1raLD+YRanJv9bSzuxPY4h9TUzwJpGuRXEzvBePNgkcFYd KeeVUXevDpC8cHgcztp/owy14w== X-Google-Smtp-Source: AGHT+IH1lRBcUubHIz93kQOurCo+8m3nu0EZoQalJ3ieURmwlYH3CSTv+IgoVsqKPZPB7xaOjJ2hAQ== X-Received: by 2002:a05:600c:290:b0:40b:377a:2ac1 with SMTP id 16-20020a05600c029000b0040b377a2ac1mr15522069wmk.20.1701351998814; Thu, 30 Nov 2023 05:46:38 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:ae84:904:6602:ec1e]) by smtp.gmail.com with ESMTPSA id n18-20020adffe12000000b0032d2489a399sm1574824wrr.49.2023.11.30.05.46.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 05:46:38 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 03/10] gpio: wm8994: use gpiochip_dup_line_label() Date: Thu, 30 Nov 2023 14:46:23 +0100 Message-Id: <20231130134630.18198-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231130134630.18198-1-brgl@bgdev.pl> References: <20231130134630.18198-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bartosz Golaszewski Use the new gpiochip_dup_line_label() helper to safely retrieve the descriptor label. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-wm8994.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/gpio/gpio-wm8994.c b/drivers/gpio/gpio-wm8994.c index f4a474cef32d..bf05c9b5882b 100644 --- a/drivers/gpio/gpio-wm8994.c +++ b/drivers/gpio/gpio-wm8994.c @@ -8,6 +8,7 @@ * */ +#include #include #include #include @@ -193,18 +194,20 @@ static void wm8994_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) for (i = 0; i < chip->ngpio; i++) { int gpio = i + chip->base; int reg; - const char *label; /* We report the GPIO even if it's not requested since * we're also reporting things like alternate * functions which apply even when the GPIO is not in * use as a GPIO. */ - label = gpiochip_is_requested(chip, i); - if (!label) - label = "Unrequested"; + char *label __free(kfree) = gpiochip_dup_line_label(chip, i); + if (IS_ERR(label)) { + dev_err(wm8994->dev, "Failed to duplicate label\n"); + continue; + } - seq_printf(s, " gpio-%-3d (%-20.20s) ", gpio, label); + seq_printf(s, " gpio-%-3d (%-20.20s) ", gpio, + label ?: "Unrequested"); reg = wm8994_reg_read(wm8994, WM8994_GPIO_1 + i); if (reg < 0) { From patchwork Thu Nov 30 13:46:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 748826 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="VIRvQo3R" Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E81F910E5 for ; Thu, 30 Nov 2023 05:46:41 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-409299277bbso7722545e9.2 for ; Thu, 30 Nov 2023 05:46:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701352000; x=1701956800; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=S7P6Y0m2hGBRRFmWFTt/dmCRHf+pQxLzAw7kKW52hRs=; b=VIRvQo3RT4aiG5EG4mKWHcQyV7GPvY5DBdbAPcDXbhbaKucRHdzGN4jts4uum9Yp+h MXxwwlcBEY3tAjPfQqiPovgDFo0WhertxXzvHgTixfkA0XUejUFeScHRjNg/EJChvwTM C2L/0X88tdGU7Bz7WOl/KsiMq0mPmLWbjBsSOo63tmZleFRRZuHITTFIOHtPv6NUfEOr xV/VbgrHCmiPRQqcPOyIcV9hAANERBqVAVPSzCN8CrMcD2YKh2c8GeNfTGzqwPTXG/Ea fxBMjec+osOQDklpJDk29qj42/3FkypLIViummhPNnLTqjmr2S0QSN3+hEK/Nzz0Srcy dCvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701352000; x=1701956800; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S7P6Y0m2hGBRRFmWFTt/dmCRHf+pQxLzAw7kKW52hRs=; b=cxAOCHLww05437Pb9GzQ5G+2ocLWWW5rYPLdFjaplAGFgsFb5+AX+iCNAqxbLsyp3K dMnNvVaLUCNkmMYO2YDW6VdqnzvinzR9cxXiiTv8CuBYJVBv+c3wnvAbqnjftLlLIW6W C7DpixbIqEjWcjj2NlxSOD1/tMUbGag6fRClrbCgnOHo3WTwbq7cmXWVfZSjKyTxD2LB bDhO5hHNlyVaBLIzTahI8HEU7HiHQB6U9MHpTQSvUbj61B7gCwx0ps49VJWY1ikzVUM1 w26xnNr9xDgdvuPfg4x6+3bDNab32nRXUzQNwEKsBJcRuik03w7glL1KbSd9eeoWwUMr Z+vQ== X-Gm-Message-State: AOJu0YxVS9Df7Ja/przwDuKZSpDCHvtB4166jASVUE9GrFRxdMxtZyZI zVhrQ7z8hKtC3+OCHjPfSgmA5H+JhXmIo8/YHjs= X-Google-Smtp-Source: AGHT+IGWQ3w4OgWs+eiKlT4hgKInIw5/57JyahFF8EAqF3mDoy9KOsBP9slLYl+6MDnBdXrI1X7t4g== X-Received: by 2002:a05:600c:46ce:b0:405:37bb:d942 with SMTP id q14-20020a05600c46ce00b0040537bbd942mr16123768wmo.4.1701352000315; Thu, 30 Nov 2023 05:46:40 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:ae84:904:6602:ec1e]) by smtp.gmail.com with ESMTPSA id n18-20020adffe12000000b0032d2489a399sm1574824wrr.49.2023.11.30.05.46.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 05:46:39 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 04/10] gpio: stmpe: use gpiochip_dup_line_label() Date: Thu, 30 Nov 2023 14:46:24 +0100 Message-Id: <20231130134630.18198-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231130134630.18198-1-brgl@bgdev.pl> References: <20231130134630.18198-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bartosz Golaszewski Use the new gpiochip_dup_line_label() helper to safely retrieve the descriptor label. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-stmpe.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c index 27cc4da53565..6c5ee81d71b3 100644 --- a/drivers/gpio/gpio-stmpe.c +++ b/drivers/gpio/gpio-stmpe.c @@ -5,6 +5,7 @@ * Author: Rabin Vincent for ST-Ericsson */ +#include #include #include #include @@ -255,7 +256,6 @@ static void stmpe_dbg_show_one(struct seq_file *s, { struct stmpe_gpio *stmpe_gpio = gpiochip_get_data(gc); struct stmpe *stmpe = stmpe_gpio->stmpe; - const char *label = gpiochip_is_requested(gc, offset); bool val = !!stmpe_gpio_get(gc, offset); u8 bank = offset / 8; u8 dir_reg = stmpe->regs[STMPE_IDX_GPDR_LSB + bank]; @@ -263,6 +263,10 @@ static void stmpe_dbg_show_one(struct seq_file *s, int ret; u8 dir; + char *label __free(kfree) = gpiochip_dup_line_label(gc, offset); + if (IS_ERR(label)) + return; + ret = stmpe_reg_read(stmpe, dir_reg); if (ret < 0) return; From patchwork Thu Nov 30 13:46:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 749599 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="gdSOQtao" Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAECC10E3 for ; Thu, 30 Nov 2023 05:46:43 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-333229dcebdso431165f8f.0 for ; Thu, 30 Nov 2023 05:46:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701352002; x=1701956802; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cffjJvUFWsxdgp9qJiLVkij+XoF+TZsz38c1WQZlyho=; b=gdSOQtaof93nM5ia61UhuHXlJsyRqcru/G05JG7W8V1FssY7r+DAfHzJne1PEcTXsF YM5G9ExjsMk8Rr5qeYZ13DnVH3LBZCQMj91lpzi1sq1n066WUmZfO8ebjceDWiYMUv63 lR+I6OhQSHuJ7HdTb24IX7LNdfcigyIVh0OtdsIfxfxVerKJuoblT1VITrUSZAyDf3n8 S9l6zab1Q+hY+sewGCicanmYoVopw2XSSY026wmft/15dYC9N6tFojxW75jjA6olC7I8 tkKVCiKU5496/SECyJMIPJAZc/ae9xT5PaCCWzEqo4elcsHb04oLQPIm7dmojCrOQrKQ Y0hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701352002; x=1701956802; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cffjJvUFWsxdgp9qJiLVkij+XoF+TZsz38c1WQZlyho=; b=q53RibhyvcnS+UDA2/MPuOeaJgvnKoycOBcF7sEW/GP4baRyQh7NNyZItJrn+em7+6 bA9CbCIywBJPksFFAKq9eVExbY9KZVo754tM5j0rsvrsdb2xeJDWlkTgbV4CX0vk9+7X ENKeCYCKjD+z+PHEDikLB1+qUjflw+ni4lfMnbZ70WBVys5JMhQwwARJPuckSIvRVJXn m1wINKYRGG8jhRnzbkx7bhq24X4uBsltNEeC412Ad1g+mYOAkyhGU+9jxvR2Ks2SEQmW klUFBywt5jE8OOiKhM2YiznZ+OwDpxOKT7aVy3CCktiOfL4Dm4SI+8byMBceR21N0PD+ iLmA== X-Gm-Message-State: AOJu0YzsWNpeSOrS5VaoV6phR/p9WZNE+n0TWp2b6UBolI4SeB4tT5ds w+7NGD/thCO65YP+97IhTd/WdQ== X-Google-Smtp-Source: AGHT+IFqmZA1KQhwkSPcUaNoBMtUmaEHugbvUiR1Onas5XzwXX7zZR0pNya8Ie3NAxw5LM70WUUmrA== X-Received: by 2002:a05:6000:36c:b0:333:18b9:27a6 with SMTP id f12-20020a056000036c00b0033318b927a6mr3490982wrf.30.1701352002295; Thu, 30 Nov 2023 05:46:42 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:ae84:904:6602:ec1e]) by smtp.gmail.com with ESMTPSA id n18-20020adffe12000000b0032d2489a399sm1574824wrr.49.2023.11.30.05.46.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 05:46:40 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 05/10] pinctrl: abx500: use gpiochip_dup_line_label() Date: Thu, 30 Nov 2023 14:46:25 +0100 Message-Id: <20231130134630.18198-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231130134630.18198-1-brgl@bgdev.pl> References: <20231130134630.18198-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bartosz Golaszewski Use the new gpiochip_dup_line_label() helper to safely retrieve the descriptor label. Signed-off-by: Bartosz Golaszewski --- drivers/pinctrl/nomadik/pinctrl-abx500.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/pinctrl/nomadik/pinctrl-abx500.c b/drivers/pinctrl/nomadik/pinctrl-abx500.c index d3c32d809bac..80e3ac333136 100644 --- a/drivers/pinctrl/nomadik/pinctrl-abx500.c +++ b/drivers/pinctrl/nomadik/pinctrl-abx500.c @@ -6,7 +6,9 @@ * * Driver allows to use AxB5xx unused pins to be used as GPIO */ + #include +#include #include #include #include @@ -453,12 +455,11 @@ static void abx500_gpio_dbg_show_one(struct seq_file *s, unsigned offset, unsigned gpio) { struct abx500_pinctrl *pct = pinctrl_dev_get_drvdata(pctldev); - const char *label = gpiochip_is_requested(chip, offset - 1); u8 gpio_offset = offset - 1; int mode = -1; bool is_out; bool pd; - int ret; + int ret = -ENOMEM; const char *modes[] = { [ABX500_DEFAULT] = "default", @@ -474,6 +475,10 @@ static void abx500_gpio_dbg_show_one(struct seq_file *s, [ABX500_GPIO_PULL_UP] = "pull up", }; + char *label __free(kfree) = gpiochip_dup_line_label(chip, offset - 1); + if (IS_ERR(label)) + goto out; + ret = abx500_gpio_get_bit(chip, AB8500_GPIO_DIR1_REG, gpio_offset, &is_out); if (ret < 0) From patchwork Thu Nov 30 13:46:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 748825 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="ZTsTAUO8" Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8DBB1700 for ; Thu, 30 Nov 2023 05:46:44 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-40859dee28cso7874025e9.0 for ; Thu, 30 Nov 2023 05:46:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701352003; x=1701956803; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/NPguL+egm1B/3hLyNOqRomxlJRtvAY3YVXSaylJwM0=; b=ZTsTAUO8Q5uQn33PwH90C0RCvf/d9jvERfPGPlJwgjE2f2UWjBaVy5KPIOpfvtUzOL zVA6S0UoM195MZr7cRWQz2g24tFJp/tg7DoN8qRtUd5mgr6+RyDZPgNjQyqUhz8L5xwn RTqqNYQmW2M8BUpfuNiuZD9pYl5oEjgoIgxfilf75+UGvc680VAok4QuHfiG7F0YjsKW PfSk7UW55TqmKvuykMhlZbryg7mX72hRc0Mv+Cd4NGbnQtRIcDWPe3poYU2U8Bw1Kecf +q+EuACXDr2HjP4pLhX990eAUw7h4rT0VLIUIeQptXzc5wKY3l+FNqkxDN0p0D6f4Rrl lj5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701352003; x=1701956803; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/NPguL+egm1B/3hLyNOqRomxlJRtvAY3YVXSaylJwM0=; b=WrSacOOmIR436HuFoP3+Vrc5lS1MrDA93ZTwfqs7mY0ZXhoWwEOh9QVDIZiUu6S1F/ O41IT37gXkRnzd9lw3CfKAZG9SfrFLx2wrfLZ3b20KNFyGD68jsTba+V3B0tLw/Milyr uEfdw7j/nmV7FNGKaCCxZklo6+JXLb6VUUHJw2B53KoSPJ3Ie3G9s8fiwzN3uZXTd9Fk xSsFUc8Fekkb5C0BV2EYXuGBtbb1UayoqVekVoSlEMfEJr817zOCcgj9lSTESzO4Z31I LKVZCNfW+ngs6lGPB6A4WdOREu5910Tg3v4GOcXstqPVsTHlrbD+ApnGITLp+rgIQ7DH +hgw== X-Gm-Message-State: AOJu0YzICy453PiUZyz8RPD2PnzjBFeJBqNqoU4dfxr93Xmox1XbW7C2 OcinyLw3kREuwomNNaET17wc5A== X-Google-Smtp-Source: AGHT+IF49lqrlVpVqkD0E02GQZF9bH8Vo6dbPgCqchTj1uNhj8pD7rKcwX/9BEAelWIERBkgSTt5dw== X-Received: by 2002:a05:600c:4592:b0:40b:26f1:57a2 with SMTP id r18-20020a05600c459200b0040b26f157a2mr16362430wmo.27.1701352003401; Thu, 30 Nov 2023 05:46:43 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:ae84:904:6602:ec1e]) by smtp.gmail.com with ESMTPSA id n18-20020adffe12000000b0032d2489a399sm1574824wrr.49.2023.11.30.05.46.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 05:46:42 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 06/10] pinctrl: nomadik: use gpiochip_dup_line_label() Date: Thu, 30 Nov 2023 14:46:26 +0100 Message-Id: <20231130134630.18198-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231130134630.18198-1-brgl@bgdev.pl> References: <20231130134630.18198-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bartosz Golaszewski Use the new gpiochip_dup_line_label() helper to safely retrieve the descriptor label. Signed-off-by: Bartosz Golaszewski --- drivers/pinctrl/nomadik/pinctrl-nomadik.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/pinctrl/nomadik/pinctrl-nomadik.c b/drivers/pinctrl/nomadik/pinctrl-nomadik.c index 863732287b1e..7911353ac97d 100644 --- a/drivers/pinctrl/nomadik/pinctrl-nomadik.c +++ b/drivers/pinctrl/nomadik/pinctrl-nomadik.c @@ -8,6 +8,7 @@ * Copyright (C) 2011-2013 Linus Walleij */ #include +#include #include #include #include @@ -917,7 +918,6 @@ static void nmk_gpio_dbg_show_one(struct seq_file *s, struct pinctrl_dev *pctldev, struct gpio_chip *chip, unsigned offset, unsigned gpio) { - const char *label = gpiochip_is_requested(chip, offset); struct nmk_gpio_chip *nmk_chip = gpiochip_get_data(chip); int mode; bool is_out; @@ -934,6 +934,10 @@ static void nmk_gpio_dbg_show_one(struct seq_file *s, [NMK_GPIO_ALT_C+4] = "altC4", }; + char *label = gpiochip_dup_line_label(chip, offset); + if (IS_ERR(label)) + return; + clk_enable(nmk_chip->clk); is_out = !!(readl(nmk_chip->addr + NMK_GPIO_DIR) & BIT(offset)); pull = !(readl(nmk_chip->addr + NMK_GPIO_PDIS) & BIT(offset)); From patchwork Thu Nov 30 13:46:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 749598 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="hPzNjZP3" Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E36D419F for ; Thu, 30 Nov 2023 05:46:45 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-332eeb16e39so611881f8f.1 for ; Thu, 30 Nov 2023 05:46:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701352004; x=1701956804; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lX1sqlEJJ4vEUK91SFq6mj5SEAnM+ha5YxcxRVGS6+w=; b=hPzNjZP3MiHNlaiBNK5uHoOFDkljjmXAmcylnoFm60bgMec4QC4X5skCapr3qftKoj PgR9V1jJg3RAPnvw7nxRVZGHqVMrpqrAtH0pxO71h7Ihfy7hGyL700YhG6gWF4cIHFux +eCppziCbu5N52REsxeqWAonVjw497Af7hLBVoD/6VUFEbZ01bPwA4iMUAGUIJqsHNT/ b1biUc5LuPW2PI3W0Yk+RSMcUmYAQoTPnAv24qPVsboxDUO12E915sDm9jcu18CYRRVl H8rjZCZFUlBL4z1GdJk6pSEkm282W9ZIiIotZQY9ZbNwicOCJOyxEc/qVeOi5ywpjYbi RgBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701352004; x=1701956804; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lX1sqlEJJ4vEUK91SFq6mj5SEAnM+ha5YxcxRVGS6+w=; b=cNL3qEXw5OIl3cWA9zO3H+0+nngZhdlWE+6V7xFPjp0SKtC3xn6cWN5VM/ATmEMIXy AK6C0jf4shsItVBZ7BTjD/unqMS87zOpKUJvusvZstly2XU7jhxG4Ye5hykhalbLwLes 6o4OHfQxASY2reAHToXH6U0ADWAvNpaVcvlv370u2Ww0XehlI+LB33XTUlF7B4nvJlZT 8EGegat//dWH0mTk8syzzleJqjg5roHB3QJy2pq+gZbBuGeEFBVImB7zK4YHz6Md1nwR +BGg5wZpMTWHxbBKTuzLWwu+4szoY36xzUfp1yUNCa6QM//W76KvMQutVZpBK8xsFwHA SEMg== X-Gm-Message-State: AOJu0YzJd1oktsDLCy+RMOW2DiTB1g2qb4QS12z/5hgn+Gu0tWHUG5R3 kbBhU/UOPRLEBjIh83a/Kv+ZCA== X-Google-Smtp-Source: AGHT+IEH8Mh7PFLu28rLEMPsJfxeGaU60dL2Y/lrZsr6Vmf/W1e5mS0Xhbaro9bpQTm02q7tKBDu7A== X-Received: by 2002:adf:f305:0:b0:333:2e28:46f5 with SMTP id i5-20020adff305000000b003332e2846f5mr53628wro.1.1701352004522; Thu, 30 Nov 2023 05:46:44 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:ae84:904:6602:ec1e]) by smtp.gmail.com with ESMTPSA id n18-20020adffe12000000b0032d2489a399sm1574824wrr.49.2023.11.30.05.46.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 05:46:43 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 07/10] pinctrl: baytrail: use gpiochip_dup_line_label() Date: Thu, 30 Nov 2023 14:46:27 +0100 Message-Id: <20231130134630.18198-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231130134630.18198-1-brgl@bgdev.pl> References: <20231130134630.18198-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bartosz Golaszewski Use the new gpiochip_dup_line_label() helper to safely retrieve the descriptor label. Signed-off-by: Bartosz Golaszewski --- drivers/pinctrl/intel/pinctrl-baytrail.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/pinctrl/intel/pinctrl-baytrail.c b/drivers/pinctrl/intel/pinctrl-baytrail.c index 3cd0798ee631..3c8c02043481 100644 --- a/drivers/pinctrl/intel/pinctrl-baytrail.c +++ b/drivers/pinctrl/intel/pinctrl-baytrail.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -1173,7 +1174,6 @@ static void byt_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) const char *pull_str = NULL; const char *pull = NULL; unsigned long flags; - const char *label; unsigned int pin; pin = vg->soc->pins[i].number; @@ -1200,9 +1200,10 @@ static void byt_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) seq_printf(s, "Pin %i: can't retrieve community\n", pin); continue; } - label = gpiochip_is_requested(chip, i); - if (!label) - label = "Unrequested"; + + char *label __free(kfree) = gpiochip_dup_line_label(chip, i); + if (IS_ERR(label)) + continue; switch (conf0 & BYT_PULL_ASSIGN_MASK) { case BYT_PULL_ASSIGN_UP: @@ -1231,7 +1232,7 @@ static void byt_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) seq_printf(s, " gpio-%-3d (%-20.20s) %s %s %s pad-%-3d offset:0x%03x mux:%d %s%s%s", pin, - label, + label ?: "Unrequested", val & BYT_INPUT_EN ? " " : "in", val & BYT_OUTPUT_EN ? " " : "out", str_hi_lo(val & BYT_LEVEL), From patchwork Thu Nov 30 13:46:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 748824 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="O52R2/k6" Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E73141704 for ; Thu, 30 Nov 2023 05:46:46 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-332e7630a9dso689648f8f.1 for ; Thu, 30 Nov 2023 05:46:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701352005; x=1701956805; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rQ4oN2yBzcOb1+JXtPZKrl0tpOl2eK1zlq9JfJmTld4=; b=O52R2/k6OkskTQsBSvj/PTMwCFu3+2ETaBaUKYlr+AhO7mU950wIaLOvdbkqLYXtwC FNvvbW3vJwBDY3GGVBdFrWqhhyEMcch0+u6A0q15Y75qGntWN18Get/3ZWiFhENlIhN3 H6ysmJdqT/OpBJ5JJjZblDE+8kvFtNZ3qMR9shrQaLnzaHJikcNbrlONwhY/QZikoMLR oS4NFXrfd1MrbaOdTfeqUcbccWPDpjJfX4vDpwz6l2bvYS5/Pb6VkTfM4GUYZ4g2TH/B wd75FZh9asf6VPD+U+0j/OPy3pBgKPkkV5zFUqcThO16qjsTshRWrDgTuvbmfP8MDeB2 MNSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701352005; x=1701956805; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rQ4oN2yBzcOb1+JXtPZKrl0tpOl2eK1zlq9JfJmTld4=; b=S/EsAoW2V31IdY5hVd8IYQOuPPQZsWuAzXdSZzhWy4l85NX5aIcMVhPzaAn3MY8raF oBqSSD4VljLRE1W7bcZwXqvBpCWEZ5UjuPrkPRvsKZP+Hxl5ZU9jtruaaQ7Z4Qs6tdm3 VD9QxdorXH1iEAre0//xISSDCrCUt3KaMNtRrYRD+xS6q4CryziecmLw5SZdWVl89Imw yzzufRF7T4P8HWzRLvHxPOycnNlSpVKeSjD7Cm7OZ5wDac9bn4bfBCA8SGJEqtWyf+GQ niYa3resbxQK6WPSiIGEJQepejrFeabZb8iioWwVmStlOtoFSuPSTy3CFm6jEFhu4hLE X83g== X-Gm-Message-State: AOJu0YwyzO3hOtzHcXf9gaymoND4t5lSv3/NlmUlVAn7FMlOJ5cGNda7 WJHBPycUAKHwCS1mE37uR8bCYZUg1mMAR1fa+bg= X-Google-Smtp-Source: AGHT+IGPtG+1uFAas3OVjot2zm3XVUDLgeyXhw2GAlVFtUSUYqhhRLnAvXvRp9OLXomSy5i1jZKXyA== X-Received: by 2002:a05:6000:114d:b0:333:2736:1e55 with SMTP id d13-20020a056000114d00b0033327361e55mr640974wrx.38.1701352005511; Thu, 30 Nov 2023 05:46:45 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:ae84:904:6602:ec1e]) by smtp.gmail.com with ESMTPSA id n18-20020adffe12000000b0032d2489a399sm1574824wrr.49.2023.11.30.05.46.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 05:46:44 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 08/10] pinctrl: sppctl: use gpiochip_dup_line_label() Date: Thu, 30 Nov 2023 14:46:28 +0100 Message-Id: <20231130134630.18198-9-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231130134630.18198-1-brgl@bgdev.pl> References: <20231130134630.18198-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bartosz Golaszewski Use the new gpiochip_dup_line_label() helper to safely retrieve the descriptor label. Signed-off-by: Bartosz Golaszewski --- drivers/pinctrl/sunplus/sppctl.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/pinctrl/sunplus/sppctl.c b/drivers/pinctrl/sunplus/sppctl.c index bb5ef391dbe4..ae156f779a16 100644 --- a/drivers/pinctrl/sunplus/sppctl.c +++ b/drivers/pinctrl/sunplus/sppctl.c @@ -4,6 +4,7 @@ * Copyright (C) Sunplus Tech / Tibbo Tech. */ +#include #include #include #include @@ -500,16 +501,15 @@ static int sppctl_gpio_set_config(struct gpio_chip *chip, unsigned int offset, static void sppctl_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) { - const char *label; int i; for (i = 0; i < chip->ngpio; i++) { - label = gpiochip_is_requested(chip, i); - if (!label) - label = ""; + char *label __free(kfree) = gpiochip_dup_line_label(chip, i); + if (IS_ERR(label)) + continue; seq_printf(s, " gpio-%03d (%-16.16s | %-16.16s)", i + chip->base, - chip->names[i], label); + chip->names[i], label ?: ""); seq_printf(s, " %c", sppctl_gpio_get_direction(chip, i) ? 'I' : 'O'); seq_printf(s, ":%d", sppctl_gpio_get(chip, i)); seq_printf(s, " %s", sppctl_first_get(chip, i) ? "gpi" : "mux"); From patchwork Thu Nov 30 13:46:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 749597 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="1zTRCSLg" Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D63CA10F3 for ; Thu, 30 Nov 2023 05:46:47 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-3316bb1303bso679868f8f.0 for ; Thu, 30 Nov 2023 05:46:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701352006; x=1701956806; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5JkcbylM7pAQh/R7rY3XvCoFJsyCRp+V27URZHzTJKg=; b=1zTRCSLgTdXz21Tn6xXOIRLL1FQTefqdWPzzetBIrrXOHVet7/oNgmIzaIBVxl3qBX Kj3oL0NiDJNwESGPukPK2xH/icTMM5wWoiB0atmwi8clfbVprTI0VtgWUXqodHjwjap2 xqF2Z2UHBkeb5N/DnI+zWuIhfBZQJXjJF9UXDRkFmW5tPBYAzKRVwuEroL9OucU8WCuS mxtcE23Qnwj2fOktg+5XCBwhmsTc5qAwOUOJkOVQiWRzyMNJhO6J5D222fzlW7NIarg+ n922xRYJYaRlAAR0IXKfVyXrgEdBx49HrnBTFkY206UW9UB2Ae8BvCmtSBK3w3B/ppsR CfCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701352006; x=1701956806; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5JkcbylM7pAQh/R7rY3XvCoFJsyCRp+V27URZHzTJKg=; b=YFoaxzM9bVZWk/071CpaLXVqdIRDAzBm1vPTfFWuW2D8qHigWkuk3lYEjXvLrWcJZs kahkZep3KVhE8eUwrX1SGJVGWzTrOxZVzdsh7bfWC3SbIj2D3ji3O9G3u6p/vCJKuUAL I+quII9s2OM5w8mhWHwuoYFomG9Fzy2pYyc6fN1DnfwGO5UHgzfTSU5JbBOQpxxxmcVM tOO+BxA0fstPAie/lw2PIerzMr9sJ9E5QI01qze8/zaOViuI+w2kTdBbROkk4B3WJQP1 TieCw+D5Q9tPcuxJxZjfiffY2S92Xqv8BBQaDXp/zPqj0d0jvvFxSsoagR0Fa31wdf50 gD7A== X-Gm-Message-State: AOJu0YxwQjuHArjoyqLShJv56/OcV+RFOhDtaJLziXAzUnC6MUYApqoc JBheH/Iq0fZROxHNWWkUFIXFSw== X-Google-Smtp-Source: AGHT+IFrUo2pYjPmikAyxVnU28S07nWrd/CCV9cpK7VFkHjyiiXqIwOTpiNbElhJRnnawaDyhekvAw== X-Received: by 2002:a5d:4c84:0:b0:32f:b407:5b77 with SMTP id z4-20020a5d4c84000000b0032fb4075b77mr15296007wrs.64.1701352006413; Thu, 30 Nov 2023 05:46:46 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:ae84:904:6602:ec1e]) by smtp.gmail.com with ESMTPSA id n18-20020adffe12000000b0032d2489a399sm1574824wrr.49.2023.11.30.05.46.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 05:46:45 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 09/10] gpiolib: use gpiochip_dup_line_label() in for_each helpers Date: Thu, 30 Nov 2023 14:46:29 +0100 Message-Id: <20231130134630.18198-10-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231130134630.18198-1-brgl@bgdev.pl> References: <20231130134630.18198-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bartosz Golaszewski Rework for_each_requested_gpio_in_range() to use the new helper to retrieve a dynamically allocated copy of the descriptor label and free it at the end of each iteration. We need to leverage the CLASS()' destructor to make sure that the label is freed even when breaking out of the loop. Signed-off-by: Bartosz Golaszewski --- include/linux/gpio/driver.h | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 9796a34e2fee..b1ed501e9ee0 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -534,17 +534,36 @@ struct gpio_chip { const char *gpiochip_is_requested(struct gpio_chip *gc, unsigned int offset); char *gpiochip_dup_line_label(struct gpio_chip *gc, unsigned int offset); + +struct _gpiochip_for_each_data { + const char **label; + int *i; +}; + +DEFINE_CLASS(_gpiochip_for_each_data, + struct _gpiochip_for_each_data, + if (*_T.label) kfree(*_T.label), + ({ struct _gpiochip_for_each_data _data = { label, i }; + *_data.i = 0; + _data; }), + const char **label, int *i) + /** * for_each_requested_gpio_in_range - iterates over requested GPIOs in a given range - * @chip: the chip to query - * @i: loop variable - * @base: first GPIO in the range - * @size: amount of GPIOs to check starting from @base - * @label: label of current GPIO + * @_chip: the chip to query + * @_i: loop variable + * @_base: first GPIO in the range + * @_size: amount of GPIOs to check starting from @base + * @_label: label of current GPIO */ -#define for_each_requested_gpio_in_range(chip, i, base, size, label) \ - for (i = 0; i < size; i++) \ - if ((label = gpiochip_is_requested(chip, base + i)) == NULL) {} else +#define for_each_requested_gpio_in_range(_chip, _i, _base, _size, _label) \ + for (CLASS(_gpiochip_for_each_data, _data)(&_label, &_i); \ + *_data.i < _size; \ + (*_data.i)++, kfree(*(_data.label)), *_data.label = NULL) \ + if ((*_data.label = \ + gpiochip_dup_line_label(_chip, _base + *_data.i)) == NULL) {} \ + else if (IS_ERR(*_data.label)) {} \ + else /* Iterates over all requested GPIO of the given @chip */ #define for_each_requested_gpio(chip, i, label) \ From patchwork Thu Nov 30 13:46:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 748823 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="rZ0hzX8D" Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A114137 for ; Thu, 30 Nov 2023 05:46:49 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-332e56363adso639577f8f.3 for ; Thu, 30 Nov 2023 05:46:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701352007; x=1701956807; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Z1Jm7DZtmPUI+tkjKaFM9ATO3Ta/nvLDLxNBysClivQ=; b=rZ0hzX8DL/w4ofgdyAKw05NRnXAh3WfKF/i92JxrjSdCSEbeP20De8vn/ZyfI6qx7v /VOPVgXWnKDAVb0dujZBwXRnyRYc6FjdA92jeh0rL2TrPk2yWzySVk7T5EQja3HTzQN5 LDIIvg3T//aNV0hNOYOkjQdaLWGfe3cuPLnqbT66h+LzaRmmU1CjvLquivalVyVwISzB 4KedLcpic7A/6C8Nfl4SBaAnNxyyhDZlii0QwwukYc8JZthuO++wdVS9Q9Q3SspeyZXM vPEb34uuWqu5Of1ne7RyLjkG+kZMGnbt3ZpELSeKocsTZCciib7HMrJyeIky7Pz+HLOc 0OUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701352007; x=1701956807; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z1Jm7DZtmPUI+tkjKaFM9ATO3Ta/nvLDLxNBysClivQ=; b=PrxOzyAoUt2f6436SefhYx+IPn20Mr6l1pKmgyyh5+oI6uCibqQyPf3Sc9pbIX06em QodZcycY+gsQ3lreFVh2EHDS1DX8fszzJrqT6lvMM3/NXh4yWRVz7Icp5EG4gSRCI5rr XDxdM1sFdTEKFK3JrPHOrIszfq3hSNWT90o1ne5bfnI+n3DLf4aG+btNNAZIsclckkjZ cls95BFccL18auFyGYr2AxG7hJM1U1Gy95U+lBFyvWgsIDp8BgbIAyb5CgxiDnG4hmpX 80aLik3QcQvCUMZNz7nKGJkAoBkUjiVWjYyqzaG7R2VeC72+T+rZz7QE6i7DgcflCHD1 3dKQ== X-Gm-Message-State: AOJu0Yz02Ju84hNC6dThNDlqzrPWfFWoSQD+1iQPEdUHwuwruoOAOu47 7Or7QCpaKcTEFAihMpCcF5H5MfYR8nxh1kBl6SA= X-Google-Smtp-Source: AGHT+IEAj1farO/m8WTaPZy/0DRdVPSgaZ/tTSVTZIibBXNvNig5A36Zldn7TIaNUdtS3M0Pnn/seQ== X-Received: by 2002:adf:f283:0:b0:333:273f:1cd with SMTP id k3-20020adff283000000b00333273f01cdmr811971wro.36.1701352007562; Thu, 30 Nov 2023 05:46:47 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:ae84:904:6602:ec1e]) by smtp.gmail.com with ESMTPSA id n18-20020adffe12000000b0032d2489a399sm1574824wrr.49.2023.11.30.05.46.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 05:46:47 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 10/10] gpiolib: remove gpiochip_is_requested() Date: Thu, 30 Nov 2023 14:46:30 +0100 Message-Id: <20231130134630.18198-11-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231130134630.18198-1-brgl@bgdev.pl> References: <20231130134630.18198-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bartosz Golaszewski We have no external users of gpiochip_is_requested(). Let's remove it and replace its internal calls with direct testing of the REQUESTED flag. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 46 ++++++++++--------------------------- include/linux/gpio/driver.h | 1 - 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 8e932e6a6a8d..3070a4f7bbb1 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1085,7 +1085,7 @@ void gpiochip_remove(struct gpio_chip *gc) spin_lock_irqsave(&gpio_lock, flags); for (i = 0; i < gdev->ngpio; i++) { - if (gpiochip_is_requested(gc, i)) + if (test_bit(FLAG_REQUESTED, &gdev->descs[i].flags)) break; } spin_unlock_irqrestore(&gpio_lock, flags); @@ -2373,33 +2373,6 @@ void gpiod_free(struct gpio_desc *desc) gpio_device_put(desc->gdev); } -/** - * gpiochip_is_requested - return string iff signal was requested - * @gc: controller managing the signal - * @offset: of signal within controller's 0..(ngpio - 1) range - * - * Returns NULL if the GPIO is not currently requested, else a string. - * The string returned is the label passed to gpio_request(); if none has been - * passed it is a meaningless, non-NULL constant. - * - * This function is for use by GPIO controller drivers. The label can - * help with diagnostics, and knowing that the signal is used as a GPIO - * can help avoid accidentally multiplexing it to another controller. - */ -const char *gpiochip_is_requested(struct gpio_chip *gc, unsigned int offset) -{ - struct gpio_desc *desc; - - desc = gpiochip_get_desc(gc, offset); - if (IS_ERR(desc)) - return NULL; - - if (test_bit(FLAG_REQUESTED, &desc->flags) == 0) - return NULL; - return desc->label; -} -EXPORT_SYMBOL_GPL(gpiochip_is_requested); - /** * gpiochip_dup_line_label - Get a copy of the consumer label. * @gc: GPIO chip controlling this line. @@ -2414,16 +2387,21 @@ EXPORT_SYMBOL_GPL(gpiochip_is_requested); */ char *gpiochip_dup_line_label(struct gpio_chip *gc, unsigned int offset) { - const char *label; + struct gpio_desc *desc; char *cpy; - label = gpiochip_is_requested(gc, offset); - if (!label) + desc = gpiochip_get_desc(gc, offset); + if (IS_ERR(desc)) return NULL; - cpy = kstrdup(label, GFP_KERNEL); - if (!cpy) - return ERR_PTR(-ENOMEM); + scoped_guard(spinlock_irqsave, &gpio_lock) { + if (!test_bit(FLAG_REQUESTED, &desc->flags)) + return NULL; + + cpy = kstrdup(desc->label, GFP_KERNEL); + if (!cpy) + return ERR_PTR(-ENOMEM); + } return cpy; } diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index b1ed501e9ee0..9a44016789c8 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -531,7 +531,6 @@ struct gpio_chip { #endif /* CONFIG_OF_GPIO */ }; -const char *gpiochip_is_requested(struct gpio_chip *gc, unsigned int offset); char *gpiochip_dup_line_label(struct gpio_chip *gc, unsigned int offset);