From patchwork Wed Nov 29 14:24:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 748341 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="crqE15JI" Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9479DF4 for ; Wed, 29 Nov 2023 06:24:24 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-40b31232bf0so54742305e9.1 for ; Wed, 29 Nov 2023 06:24:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701267863; x=1701872663; 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=crqE15JIivDRD7HPz9UTlXpZe8y6b3M0VcIyqiQVPCgE+EgTIuWAAjCRr8hdm5pIg5 LHoZXe1ssMuLx7Ib1ksYYzD+7ipHUTZ5LLmpuHpWIPkRiHs8g37qiPeMtNq7RHJBCPKw tPR08+j7Do9gwDUkDi811MWKlE8nHUteE6W4Ge5vzYAqz4oq6wYHQ/72e10JG3Sct41s ldeGuzNoJcUmac9UgntzSZyvTGFoAAnluth+IO8yOUd9DSWbog4GOJ8EGEruztwtgDYl Vip9o8zX5WiBDZzdVkzV9cE1wouOKid3FvHM7Gikn4WG3gvPx5xhrdR5IjBsHxxofJb0 IXfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701267863; x=1701872663; 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=DJTX/rww0Le2dbgXJuakhKtDKwqUDtDso5tCSH/gbM6OYaItJAn7LVND4Ni9rtytXP I1AoswvS70nsjEL9Kc7TdkZsVdvzqzIbrEtxa129pAXCmHCwsSovOH0i4bIhSsIq7O16 PfGD9uIqMMS01nuhWGv2BLoOZ4Yinhlcn2lG/BALdcVuQp5QPpyJAADyLJDnWgfH3oE+ XjoAxplpIATIvFIjWGrRcYv0eK89tH9UP8zdaqCYG4ic7yHqCfUmN3CRkxzCpv/PlyPd /bnRgO5KfK8JP3UM6+K5hdJKTr/vvivHZ9jmtoP74GgzCAOB+VT02UQBY+fPiH9sqq4b zl6w== X-Gm-Message-State: AOJu0Yzq0lLQmKAZW+E+gokMLI+noANykS6otifi/B4ChyO+nE3Tn3s9 5GRwITk1YIRJ/OrT8fzyA6/TEA== X-Google-Smtp-Source: AGHT+IF+n+Bguen0U7DsO4xPBjVSnhr/bzmyaozCPrrt3u3QTE29we1fJcSv4k6cx5guAABEETFQtA== X-Received: by 2002:a05:600c:3510:b0:40b:45e2:1f56 with SMTP id h16-20020a05600c351000b0040b45e21f56mr6396343wmq.39.1701267862985; Wed, 29 Nov 2023 06:24:22 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4520:2f25:4d3a:4adf]) by smtp.gmail.com with ESMTPSA id n40-20020a05600c3ba800b0040b34720206sm2406848wms.12.2023.11.29.06.24.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 06:24:22 -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 01/10] gpiolib: provide gpiochip_dup_line_label() Date: Wed, 29 Nov 2023 15:24:02 +0100 Message-Id: <20231129142411.76863-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231129142411.76863-1-brgl@bgdev.pl> References: <20231129142411.76863-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 Wed Nov 29 14:24:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 749622 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="KkU0Icqx" Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1637A197 for ; Wed, 29 Nov 2023 06:24:26 -0800 (PST) Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2c9c18e7990so6391811fa.2 for ; Wed, 29 Nov 2023 06:24:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701267864; x=1701872664; 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=KkU0Icqx8HR3nwLcQajkvSFBK6+OUPGRRyjgnUa1BO8ra9MFdWS/NPuH7KOwRzcrOR yzAR/a2ihBfjZPg+C9hGAQ7lGEWRRI62VXFF0iOVOQlgpvgw0s4O4V779l6jfUuTucXP VSzqwqawXHrNtaC+3bf7ey+Zx90e4+zRxXBelqlL5mHcBtuOrioNCnhLjK+/5QWSFV7G /0vWvU1pVhxTfiIcAbzUQwJIK6O+Tt2yIp2WaN7zBiohDgOD5nk+ZRSEG/sJakvuOdm8 RXSsaJY2tpfR8arbUolhMOWoE+SrdIcmhEQVywHWOjJKQxOyHTlq+tVZj1zYcBgg7l73 j8+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701267864; x=1701872664; 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=WBLlD+H+YGjoZitThqy4QDNdLzh0PJsW6WiY5jqRfUSoAV4C1IlUL0ZxLU/ji4Nhwo mUbQdyZeiH7YHJzi1TnvPxkNbEtBM2ycoKSjD/4VGQ4rPQ31bWIf6pAC1FsB5K2j6q25 cWfYZ61A7mGvnJZbsPFHU1RHI+IkJQ1306Sri8qQSL8q/fWzvRQxGO2I+/vw1UKTldi7 R+n/7nKlgb5vTRFRoQKeTZ/3AzaU9HbwmKhOA/vxzjjWEjvlrNwgU6drt4TtX5766HJe No/3YEp6gvjwDOYDnP0fnxIp7jh8D5GEZBfLfqaOb+XkhF26q/vA6cssL1k3JW5leyn7 w6Tw== X-Gm-Message-State: AOJu0YzGAi3nIpK1Z2Dxadh6+ntzIrIgzuSvuQqPsvLieN1QWWMeiXmQ ZJLfJzFkg7hxQrFWgTqEo+gGSw== X-Google-Smtp-Source: AGHT+IEkczzI1R8jS+gFL7GKFMTH6r1tr8NT05t7eLAvQCb5G46R9vrMwpDmkFfL0LuzEN/A2vrYpQ== X-Received: by 2002:a2e:8804:0:b0:2c9:b84a:1485 with SMTP id x4-20020a2e8804000000b002c9b84a1485mr2878937ljh.7.1701267864148; Wed, 29 Nov 2023 06:24:24 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4520:2f25:4d3a:4adf]) by smtp.gmail.com with ESMTPSA id n40-20020a05600c3ba800b0040b34720206sm2406848wms.12.2023.11.29.06.24.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 06:24:23 -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 02/10] gpio: wm831x: use gpiochip_dup_line_label() Date: Wed, 29 Nov 2023 15:24:03 +0100 Message-Id: <20231129142411.76863-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231129142411.76863-1-brgl@bgdev.pl> References: <20231129142411.76863-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 Wed Nov 29 14:24:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 748340 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="LmLhgxQO" Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E655FAF for ; Wed, 29 Nov 2023 06:24:26 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-40b4c2ef5cdso16055665e9.2 for ; Wed, 29 Nov 2023 06:24:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701267865; x=1701872665; 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=LmLhgxQO3nHYMI2D6VsD6PUbZTI4P8P8pyL71/ah7j5htcKAuq+fZmhoQhie6rGmor EM0ExqKdJJ/qjlPCo1CK+sFFDHX23cP0LFR1Ohy3gQ9VauskBGHXtJxBbTI9hBGyfkgP wbRagLLQkNnlBc6ldAODpY370cVnp5PrScBcojZHEG5x+6I6SN2P5RUXHPRbNqbldIT7 RAxjNp5OPdwL6TkFiU7IHgHcr9TthmxfotCSkMnFB0ak6+sWThNXrFKXqiaUDf7HVvTj vX7QukghLx/yXrgyIYVE4bT/EuacWr1UBEwzNGgVRVDQsUmve4N/bGRLaRDkH0crBs8G 6eAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701267865; x=1701872665; 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=SUlf4YIDq8+PToVaNI8Tb6cYe1/16NhJ0F5o3trKRxr9QxY4CuCTHvLD8eSkIiFn3E +Ldbht0Sg3Vi/edtt/ySU459+mvzYs8+dOPGCIGclbjgqg9MlojzT/itQEgYdlzbfaqE AT/iFjd6Ct8WIYQQf83izxuB9w7333PhH1ffAjdFmIgv3FRstZrFLieUhBIDHdbcKgni /hCy9QDIT2JxWGgmiyl+0NNdtYMDa/i5hIRV3wFS/7okEjwSmbTiHd95NOeaX1Q53W2H 81xIC0Rti/TkmGm4JK3ezA6LAik8QcugME9VyHm46+ODb21D4xN1MlWXuZM/qG5rOAjf mOnQ== X-Gm-Message-State: AOJu0YzxHC3jqEwN/mMAUqqtxGS+Z/3iHRhwfc4QPas+8x3w79xSfYGk vsqmwwKmQ3Xf+U+Xn0Nmn0JDOA== X-Google-Smtp-Source: AGHT+IGzwxqZ/cr1y8ySwFiJGA66fa+vba4/Je/dhnGCBrRLJyMyF58vXXnPj3KEdcBW2tko7WDfpw== X-Received: by 2002:a05:600c:138e:b0:40b:3605:acda with SMTP id u14-20020a05600c138e00b0040b3605acdamr14504750wmf.25.1701267865284; Wed, 29 Nov 2023 06:24:25 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4520:2f25:4d3a:4adf]) by smtp.gmail.com with ESMTPSA id n40-20020a05600c3ba800b0040b34720206sm2406848wms.12.2023.11.29.06.24.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 06:24:24 -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 03/10] gpio: wm8994: use gpiochip_dup_line_label() Date: Wed, 29 Nov 2023 15:24:04 +0100 Message-Id: <20231129142411.76863-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231129142411.76863-1-brgl@bgdev.pl> References: <20231129142411.76863-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 Wed Nov 29 14:24:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 749621 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="fmMbM2Xq" Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBC0FDD for ; Wed, 29 Nov 2023 06:24:27 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40b5155e154so8429335e9.3 for ; Wed, 29 Nov 2023 06:24:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701267866; x=1701872666; 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=fmMbM2XquS3hB1agy/V7FOyts6vnMhNULjoxw3yQIOw30649AXKQNfFdu/Yh9+TYDH RSyMOtSvQ9PPxQ78bPtCbWpydycAS5/VouqSBEUpWV8OKHktZsGdzKpd8NwRKd1VBeQH 0zsj+5mhPk+6aahgwNALOrFbSAYMTD9Ut1MIHUv9U2J8fgEOULgwwN2cImtuxtPsJ+uN EeV6BEWkM+GEeSF0ud2cj0n2p/5TxRlOxbbbYQ0PJJgI3coki+so9VXsyKKVEj3crfgw r3i+bD3n/rnVa9DyXcLlcvVS3fUlg+YDkARJPjnlz0VQZytJO/SHUkZM1ZVWqChKQ7KT kT7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701267866; x=1701872666; 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=MQLDoa9kXSu9bm5JtllanpPi+3w/f87zRR1+APwNaTytar+wqry06aI6lhjH3Ve2ID M0dhAABkMjdJZEuaK55jHlEXjk578a1V4t4MWSzrna3rEGZcuQtU7peQsHjfmPdmmpXN 0KNrM10AOb6uiQ1PO14P17QJgTy/0yPuIUDiqSKQddA/y6Sp3kSSBXzBB233wRuQngNC UJo8L9PE4kXMy/a7xhwlN4tV5ztMcflUh8VJIv4zzk3PUzXv/rAJD5Rh4L4qE87y8d2T QCVWN28+VcuTqXzTQPfVbRMSqJYKP/2tB1+gp6ehLRNpEXAUJZ9ZrM0ZleGKJcKtiejN p2Tw== X-Gm-Message-State: AOJu0YzZr1AbFwbAadUoozrTc4eJ3odU2BifZVGGZmU8lcv7t0I3rNvE aID9IOM3pxJhwJjFF5hYcLk5Qw== X-Google-Smtp-Source: AGHT+IE9BfsGxTjT5b568IE45xWg41xMIwavHOZrpDPhRpbyx+zNNYTDpinUA7Bc7rGGWxcYdxfPjw== X-Received: by 2002:a05:600c:4f82:b0:40b:2b42:a1c9 with SMTP id n2-20020a05600c4f8200b0040b2b42a1c9mr12880421wmq.23.1701267866421; Wed, 29 Nov 2023 06:24:26 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4520:2f25:4d3a:4adf]) by smtp.gmail.com with ESMTPSA id n40-20020a05600c3ba800b0040b34720206sm2406848wms.12.2023.11.29.06.24.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 06:24:25 -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 04/10] gpio: stmpe: use gpiochip_dup_line_label() Date: Wed, 29 Nov 2023 15:24:05 +0100 Message-Id: <20231129142411.76863-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231129142411.76863-1-brgl@bgdev.pl> References: <20231129142411.76863-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 Wed Nov 29 14:24:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 748339 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="eJOMdLkg" Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC527D50 for ; Wed, 29 Nov 2023 06:24:28 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-3316d3d11e1so625682f8f.0 for ; Wed, 29 Nov 2023 06:24:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701267867; x=1701872667; 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=eJOMdLkgwF0Ty0Q4LK/MdwHWMSA87R7mOY3U5811JahdHvufQqSwpJ8TNXUc5rDStt ZlMWvdvXc/JWTa08y2sGchYB27GD/iN2/cM6SHLMCEhX32dY3dKOPY+kmyRARL1G/uqm l+yBMVhECL061xOFwcHGUTA7NGP2bkB+tNrWMbibeQVa2Ltbqvnj89/v4rVTmsbnZotQ Qf+X7aLjpYJfo1imRq1VbKaUGooldHovIsHYxDYXg+dduDvV3iKU5QXZpAkbSQJDjtqL 8RRjcQdNQNFjE6Hk7+8vo7GEUHdGhMCbGLks1V7hp6DL5FgTOPDgRmU7h863QZzm5I8X mR3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701267867; x=1701872667; 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=a/lIPH2PP7FxiQlABwDaP6K7F7Tkcrpb+mZy/+zQcNixmulU7phTPuJrGVFefBSHBT mqV+VaXM3zCqBnzI40GhIs+hrqXvSHlSalT9MQie7oKDwli3J99q3v24Nbi7zIXoNXXR XxvY1R8ESezQO9zwksnu3CD2fQSOLnn+HbTjUYNFSVmi4OnoMc7a5t1Xt1cg4wNrpcV9 1qOPB1Mo6gxeaM9BFreHEk66fjQDQQCCfYlHoaNHtlRNKgh+upMvjh8TL+cGF0O7M0M/ mgRt2ntYk5ITTgXJAMljX5cUR0iB7LfPzAooSGV5hxmu2jes2EuxKsdCGqk2p4yDpqD/ ulLA== X-Gm-Message-State: AOJu0YxzlBjxiICxi2MIRctzesjVfWyQDDNekJxY0tpE4J3OqFMy9e11 gp1VTtfw7Dk9Kg3isKbQrsFjUA== X-Google-Smtp-Source: AGHT+IHjpWoseIDs6Br+Qwb1chr8KZN2ND/DdsGAdWy/f8A9EoGm5jKOkW2ftsdvCiW48Ean+8Q3zQ== X-Received: by 2002:a5d:64e3:0:b0:333:47e:4cf4 with SMTP id g3-20020a5d64e3000000b00333047e4cf4mr7806142wri.15.1701267867269; Wed, 29 Nov 2023 06:24:27 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4520:2f25:4d3a:4adf]) by smtp.gmail.com with ESMTPSA id n40-20020a05600c3ba800b0040b34720206sm2406848wms.12.2023.11.29.06.24.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 06:24:26 -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 05/10] pinctrl: abx500: use gpiochip_dup_line_label() Date: Wed, 29 Nov 2023 15:24:06 +0100 Message-Id: <20231129142411.76863-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231129142411.76863-1-brgl@bgdev.pl> References: <20231129142411.76863-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 Wed Nov 29 14:24:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 749620 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="zmQJ4Ys4" 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 AF958197 for ; Wed, 29 Nov 2023 06:24:29 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40b4a8db331so19249925e9.3 for ; Wed, 29 Nov 2023 06:24:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701267868; x=1701872668; 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=zmQJ4Ys49CuOfhXncDZdxnjlU0VLCAlLpshYRS+4NlZtnoC2PqhvVwi12XBV+5E/fs /YZA9Qp/Ul69d90eO5E/O+jw9TO1B/5GId7K3nfbtE2uSiKUhiWmldQRw/nSynxooLGj NASpy9sbNwUzTMlu4IAdolN2xvpA/1foW5hqbLEDYbjgDhUc+j5rHuSKxxOPy8UIWtUc s/T6T4aPXSNpWhRsr6FlAyVFqwwgJq1ZevPf00uzIL2QAXRYlcsQT2eJ3ObiG8pBmOgJ E3yqMES9ukpwMza18wvFtQg3O92NHp3iMOBHlGFZAcAX9ZGEo9PpVmHwcSyYZtD+xCna jKdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701267868; x=1701872668; 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=mVINxhYf6IDEZQdErZobb6cvMACcJK1DZY9CvdZLpAMQK2Cn4dsLAIRB8ytw0owyTE p5m1cx7eyS+XE2cjZF2/Gr2084Mo2mpvRa1J67rbdB94s1MfWrIaY3uXU99uRnm9CRb2 c9tYUXjV8s8cjGDVaw7k/liLBgHyeTImSDCWp11kOx4fKG6VLUekQrob9csq9q8M3xbG gA1xQthJzLlXBdln0WIPTKqu3wZ+XX6WfNIC93fPY+J18jTJV/Ag2LMXfEREMi3TadSg eJOKt709WOqxYsiJ0Ucl0DMNQyzWJ9dbFsT+DS0psdkvYaxeJVT4KyLPc+e6eEB9RAqs ekwQ== X-Gm-Message-State: AOJu0Yzdi2WVkMjI1NHsW1t8kfgPh5mqNC59dGLlePlKAJUdojHL5jsD OAAJIabQmdXdWWzG6Zgr3S7Spw== X-Google-Smtp-Source: AGHT+IEIUIxZE0FFWq33NVEE0m0n6KKNo0xXx+LcPgG8+tEi5gE5dQ6JB2ZNU3b7fWCs507DrqnJhQ== X-Received: by 2002:a05:600c:4f15:b0:405:3ae6:2413 with SMTP id l21-20020a05600c4f1500b004053ae62413mr10800607wmq.25.1701267868115; Wed, 29 Nov 2023 06:24:28 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4520:2f25:4d3a:4adf]) by smtp.gmail.com with ESMTPSA id n40-20020a05600c3ba800b0040b34720206sm2406848wms.12.2023.11.29.06.24.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 06:24:27 -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 06/10] pinctrl: nomadik: use gpiochip_dup_line_label() Date: Wed, 29 Nov 2023 15:24:07 +0100 Message-Id: <20231129142411.76863-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231129142411.76863-1-brgl@bgdev.pl> References: <20231129142411.76863-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 Wed Nov 29 14:24:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 748338 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="cmui+8oU" Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C534DD for ; Wed, 29 Nov 2023 06:24:31 -0800 (PST) Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2c9b77be7ceso22713781fa.2 for ; Wed, 29 Nov 2023 06:24:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701267869; x=1701872669; 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=cmui+8oUvf4Ks+gTyWIBhQm5JG7ZMZ4iUa+RgGSbI1FOXXh9qfUqryLfKlHRm/NsR8 3sTfsLnrqes8B593KPQegLIqTkPCQIOTPGwqmxWQsxxNfg4po7gJhejOJJdSe2w0u5wA 6ulnaQENKCaSj9XjN1tQiW9dcMQ0iNIwMbLAsSqIAJXYeUAbjnLbB7m3sOJu18bNTQEG 7MYUe/nOcN3msrJCjSoDfUBtJg1ZtYInl6Qz+zmigAqKSkk5BXJ/3WdTlpPRKbj9wqZq zqYKZIj7A78lP+mkRl1K6S7ahdKTqSzi3Umd2dqBup5tKd7kR/FglystB0cuEw+uMHc2 dkdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701267869; x=1701872669; 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=pI7k6hB00ldZBbOuJ93lqypdOYCXtYgL1Nl5PyFO0dN7dq8Rwmck5U8eo6iDNDGuUC xUjjnn9D9+VZ+/JMudFC2OKh1TsPn9e6XZftoh1fuxkpjW6tYOq+YKpr3wgyUT1CqXI/ 7BC5iJkvXZotsbs+RDVOswmjZs1UJbuKIH6Mnpsy8nKKW9dFpev2I0dxGU+kl5vRT0Li 7Lcjo1m0cfsusucpikJH8QmpJVzYb4+yukXIGZXaJEqRhbdZ+8hlvNIO4m4/EUMewuGw J6NI0kM8Pnd7zPeTHngd7CKSHRXd8uMpuAOgC2PUsALdHtm15jOMu429qHSU1luW8rnK ta4A== X-Gm-Message-State: AOJu0YxmENFr+RU2/HF59pFrLsUQEFZ1vx+DijvhC1gai4BvVeDhw/6A gxj3HOYQJ/EMvr5yUJSZhoOkyg== X-Google-Smtp-Source: AGHT+IFjEBWan0C97HdNCiQeMtPtXLlhZluROT5dGRXGCE0TfLtIbmQkWSsz4iIIEozMicZGD6j8hg== X-Received: by 2002:a2e:9855:0:b0:2c9:c00a:c28e with SMTP id e21-20020a2e9855000000b002c9c00ac28emr1331701ljj.33.1701267869205; Wed, 29 Nov 2023 06:24:29 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4520:2f25:4d3a:4adf]) by smtp.gmail.com with ESMTPSA id n40-20020a05600c3ba800b0040b34720206sm2406848wms.12.2023.11.29.06.24.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 06:24:28 -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 07/10] pinctrl: baytrail: use gpiochip_dup_line_label() Date: Wed, 29 Nov 2023 15:24:08 +0100 Message-Id: <20231129142411.76863-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231129142411.76863-1-brgl@bgdev.pl> References: <20231129142411.76863-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 Wed Nov 29 14:24:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 749619 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="fSB4WGkZ" Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30A3010C6 for ; Wed, 29 Nov 2023 06:24:32 -0800 (PST) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2c88b7e69dfso81569481fa.0 for ; Wed, 29 Nov 2023 06:24:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701267870; x=1701872670; 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=fSB4WGkZG35mb/eSTil6wJYHacf7Xy2ySbuqtE9u4PIxHoqiNA9geqZmdtJfQR8jFZ PoM9Sm2m6/g3RKGh5M9zYdJo9+06YpdBb34gqjxqXZzfBq5N5ucgL1SqcC9CVhWFbmWl MAhOGo8I5Iz31n0B97Y6/4WjK0J9mt9LbTWH11ptTjP2WvTf9j80SBoxBr4+IhzTbU39 cb/wepHsOFYajQuRCP265xQ8E4GLlBJaqwEJN2R+Wl1v/S4F7u/qgTpSmcQbD8lH+Q+q AR+fgiK99L1kJyju2sbD3TKCLLhoEKM+EIOR8/WYUSh6/XtRP7vS/7vgw4zMZwMj1VoF I5HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701267870; x=1701872670; 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=DXvrXTXd5szTVEcvmMNd1c5QP2OHymRnWB/BewLnqBMf/REs3NRdqazi4N8LJKkxfB y1HuSMBZR3EMQu7XtfwD//hNqXaMyP9DMgAaqXmgR0noSEfEW+S0Dluc5hSTiGAwZJSK rjkxPUZQ062JLs6PgG9BLX/AZ5yMYxNZXrgr5nDNcVphMtpUUuHVDMAGaWYPRRMzhVmU zmxJdB6AdjkqfMJU8w3NpVP0j+SBjoY5b1jNz2CwqpvB3jjxgkc6UJzfKZmYHYd1/1nS WNtW/04zZNqJ/2S80U3bEHiuLJEmALWclMOGN50p+oJd7vXjX/52qhcYC3gjj+o1bjcf rsLw== X-Gm-Message-State: AOJu0YzpxATn3Wy7mzyeOz+ZIvQ1DIn5TcpCz/Y3D3uVSUNGqPeKQVrx gxr+LJALXcL4vitsiJG0dO8aiQ== X-Google-Smtp-Source: AGHT+IEM0ferBCaODHhUulOSAu3F+ckHAPew6loNpc69zlAeek/BqCYvoUTSVE7JAcLnIlSQGFuJ5w== X-Received: by 2002:a2e:97d6:0:b0:2c5:16c0:6239 with SMTP id m22-20020a2e97d6000000b002c516c06239mr12471205ljj.51.1701267870294; Wed, 29 Nov 2023 06:24:30 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4520:2f25:4d3a:4adf]) by smtp.gmail.com with ESMTPSA id n40-20020a05600c3ba800b0040b34720206sm2406848wms.12.2023.11.29.06.24.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 06:24:29 -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 08/10] pinctrl: sppctl: use gpiochip_dup_line_label() Date: Wed, 29 Nov 2023 15:24:09 +0100 Message-Id: <20231129142411.76863-9-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231129142411.76863-1-brgl@bgdev.pl> References: <20231129142411.76863-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 Wed Nov 29 14:24:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 748337 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="b2ZS6wga" Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C666C10D1 for ; Wed, 29 Nov 2023 06:24:32 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40b5155e154so8430175e9.3 for ; Wed, 29 Nov 2023 06:24:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701267871; x=1701872671; 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=fr1TOXD+5EiiAKWXZPldv8mvv4Hxfk7OfOL3Vw/aLQs=; b=b2ZS6wga3v9XoxDjeUSryuw1P4M6qlXzKNKjP25dKpR2fGbQkDw6OlONxWl6vU+60W vBvnnoN19QdApekYchbioO0xkDXZWeS9uGMY315nz8+jc9GCZfp1FYrzehNWBL3In4Hp kuqk02sODqkYicoWGnwkgmyYg/mVEer1w2PUL+rrBQYRsF4+6+BBdcXK6SKQQQ9fFzKR 4/sMLazccw4ZJkEXhVOOBRWtMPpjHfAQDR1CE4JTd+YKPXRU8Al4N+12V5AF0MkwYo0Q awHCZ913nFmMcU8BYLhjfODTfHBJXm9gQPVuVQVpsp4quE9tPp9Yz6ZjOMmDGQJ+0n+i 6q2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701267871; x=1701872671; 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=fr1TOXD+5EiiAKWXZPldv8mvv4Hxfk7OfOL3Vw/aLQs=; b=Fyd+l8UCmXiFCkl6O55oU73mqVpelXSiJ88ev50wiMRlgH0XxBlWcAbxxkH9KuEMDz P8Z3ZIy4CAuBKkk/h5pwNCxEovrr+YSBoWNw4MXIeT450BGHl73ZzaSEwlU/Lj24PyT0 T5pRyJbPQspH3KpQfPuAzSKrQ2b3/QLgQW5lWXo/nzlmk1pxWEHBwEuYx5Z3XRGerDeJ ZtA0KSpR6q2znTZ2V7nGirAVZ2iPwdnentDqiHw8SkqckJAuIHKWJBcRfEZvLHO7dbi+ XIbTqsh20BpQY34Z4dmhLd46jaP0MVPkqHpCFLkYkUolZ7lSgkYUUaJ9KahHiHf+xP3k dEKQ== X-Gm-Message-State: AOJu0YzYYRP2uLexnPG7WJ9HMTeGTxkSpJjKPWE0r1mXnBtGW6qmW/zJ fqJbYVVZ1j3YbQHRJIEzz/klqQ== X-Google-Smtp-Source: AGHT+IGXheSQA/LGa1P9UW8p+tbga/Gnp13k7Ued9roRRHog+HQ8GZ429C+BiN61YuawC8IhiKC8tw== X-Received: by 2002:a05:600c:1c9d:b0:408:434c:dae7 with SMTP id k29-20020a05600c1c9d00b00408434cdae7mr10543652wms.2.1701267871356; Wed, 29 Nov 2023 06:24:31 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4520:2f25:4d3a:4adf]) by smtp.gmail.com with ESMTPSA id n40-20020a05600c3ba800b0040b34720206sm2406848wms.12.2023.11.29.06.24.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 06:24:30 -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 09/10] gpiolib: use gpiochip_dup_line_label() in for_each helpers Date: Wed, 29 Nov 2023 15:24:10 +0100 Message-Id: <20231129142411.76863-10-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231129142411.76863-1-brgl@bgdev.pl> References: <20231129142411.76863-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. Signed-off-by: Bartosz Golaszewski --- include/linux/gpio/driver.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 9796a34e2fee..6405f6d454af 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -543,8 +543,10 @@ char *gpiochip_dup_line_label(struct gpio_chip *gc, unsigned int offset); * @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 + for (i = 0; i < size; i++, kfree(label)) \ + if ((label = gpiochip_dup_line_label(chip, base + i)) == NULL) {} \ + else if (IS_ERR(label)) {} \ + else /* Iterates over all requested GPIO of the given @chip */ #define for_each_requested_gpio(chip, i, label) \ From patchwork Wed Nov 29 14:24:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 749618 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="2JS/SOyd" Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9F9A10E6 for ; Wed, 29 Nov 2023 06:24:33 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-40b4744d603so27777155e9.2 for ; Wed, 29 Nov 2023 06:24:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701267872; x=1701872672; 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=q4MUC5eIDni/buanxrUZQlfU7mM7/HRQ/uDUqZDkwLQ=; b=2JS/SOydiknEuqmFOYDnpQfOVtxGkBRZY8XxDaZBUM0fS0jUw1xbvXhpHfg+ll24M+ s25G4Ll0kIQpwCF0XCy+nAE+JIF2QWIln1/wSFxrrBfryHwX/0aZTgaQ7RYgWWIfenok hyYs9xJNsYbwURFUyXfa/ELuGq3jtb5rPSaKBoe6wlBohBeQo0IJWmS6x0EFq5XT0QiB AmsmqOwI6Sq0N5SVE1qH+xcHsuOxZKPR4hiSbacH950E/4SPQ0KUQ4eUz+DMiwqlrTq4 KalbYjiJlpeLI0ccbYVXBCu+o7KLSieBN9tP4rDswlK6XAQ6trVmVDOHg0K4rw4rzWPP 0iJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701267872; x=1701872672; 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=q4MUC5eIDni/buanxrUZQlfU7mM7/HRQ/uDUqZDkwLQ=; b=QQbfEFmfr5ocYRMAiiZ9ktVsxV/rUyG9f/2CGOdkYZDDxNCXLP0iSlaNrk1QxHcVqT 9mV3AmpNhHG1gv22+1lDpBIv/oUPPp9qSdaow6Z47Ri3VyPfie4RIXf7JzkwEMsWw9Sz akBW+jDxi3uWNv3ND8fnAM9WKF1Vg7QO5bHG3FEKiENOQ42rdCuBjLeIpi9gjbHiqvwj eRT/qnO0K3pdoWoSQZyJitGgpKkSZPaSJXHPKrbyXLS3W/dB1P8hFKXOyFZlYhIJ94Q8 4s51u8EnZHib7FzQvQOPUKIon65Q8EAeHbl6kCl5yZWlsm7+3Pi7y5EaDrmH51s3wguo psuA== X-Gm-Message-State: AOJu0YxJ1Ex2nUKveysJ/PhilHRZKYnw0VOEGflWIlQkuLFkbRlJ/489 4EMLsjKrx3eWhPXXVZ0q1YZ4Ig== X-Google-Smtp-Source: AGHT+IEIhjE3hyoM/RXTc0cdiJwPMiOTEp4g658vnqp6nZCY6jMei2HDNMvjcMgAUPil9kSpdJQRzA== X-Received: by 2002:a05:600c:3ca0:b0:40b:37d9:b646 with SMTP id bg32-20020a05600c3ca000b0040b37d9b646mr11047907wmb.3.1701267872204; Wed, 29 Nov 2023 06:24:32 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4520:2f25:4d3a:4adf]) by smtp.gmail.com with ESMTPSA id n40-20020a05600c3ba800b0040b34720206sm2406848wms.12.2023.11.29.06.24.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 06:24:31 -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 10/10] gpiolib: remove gpiochip_is_requested() Date: Wed, 29 Nov 2023 15:24:11 +0100 Message-Id: <20231129142411.76863-11-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231129142411.76863-1-brgl@bgdev.pl> References: <20231129142411.76863-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 6405f6d454af..1679e6fa5469 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); /**