public inbox for linux-gpio@vger.kernel.org
 help / color / mirror / Atom feed
From: Rosen Penev <rosenp@gmail.com>
To: linux-gpio@vger.kernel.org
Cc: Linus Walleij <linusw@kernel.org>,
	Bartosz Golaszewski <brgl@kernel.org>,
	linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] gpio: cs5535: use dynamically allocated priv struct
Date: Thu, 12 Mar 2026 17:12:09 -0700	[thread overview]
Message-ID: <20260313001209.117823-1-rosenp@gmail.com> (raw)

Static allocation is deprecated.

Remove the FIXME as gpiochip_add_data allows using gpiod_get_data.
No need for container_of.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/gpio/gpio-cs5535.c | 48 +++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 27 deletions(-)

diff --git a/drivers/gpio/gpio-cs5535.c b/drivers/gpio/gpio-cs5535.c
index 8affe4e9f90e..5f5373d86397 100644
--- a/drivers/gpio/gpio-cs5535.c
+++ b/drivers/gpio/gpio-cs5535.c
@@ -39,10 +39,6 @@ static ulong mask = GPIO_DEFAULT_MASK;
 module_param_named(mask, mask, ulong, 0444);
 MODULE_PARM_DESC(mask, "GPIO channel mask.");
 
-/*
- * FIXME: convert this singleton driver to use the state container
- * design pattern, see Documentation/driver-api/driver-model/design-patterns.rst
- */
 static struct cs5535_gpio_chip {
 	struct gpio_chip chip;
 	resource_size_t base;
@@ -285,30 +281,29 @@ static const char * const cs5535_gpio_names[] = {
 	"GPIO28", NULL, NULL, NULL,
 };
 
-static struct cs5535_gpio_chip cs5535_gpio_chip = {
-	.chip = {
-		.owner = THIS_MODULE,
-		.label = DRV_NAME,
-
-		.base = 0,
-		.ngpio = 32,
-		.names = cs5535_gpio_names,
-		.request = chip_gpio_request,
-
-		.get = chip_gpio_get,
-		.set = chip_gpio_set,
-
-		.direction_input = chip_direction_input,
-		.direction_output = chip_direction_output,
-	},
-};
-
 static int cs5535_gpio_probe(struct platform_device *pdev)
 {
+	struct cs5535_gpio_chip *priv;
+	struct gpio_chip *gc;
 	struct resource *res;
 	int err = -EIO;
 	ulong mask_orig = mask;
 
+	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	gc = &priv->chip;
+	gc->owner = THIS_MODULE;
+	gc->label = DRV_NAME;
+	gc->ngpio = 32;
+	gc->names = cs5535_gpio_names;
+	gc->request = chip_gpio_request;
+	gc->get = chip_gpio_get;
+	gc->set = chip_gpio_set;
+	gc->direction_input = chip_direction_input;
+	gc->direction_output = chip_direction_output;
+
 	/* There are two ways to get the GPIO base address; one is by
 	 * fetching it from MSR_LBAR_GPIO, the other is by reading the
 	 * PCI BAR info.  The latter method is easier (especially across
@@ -329,9 +324,9 @@ static int cs5535_gpio_probe(struct platform_device *pdev)
 	}
 
 	/* set up the driver-specific struct */
-	cs5535_gpio_chip.base = res->start;
-	cs5535_gpio_chip.pdev = pdev;
-	spin_lock_init(&cs5535_gpio_chip.lock);
+	priv->base = res->start;
+	priv->pdev = pdev;
+	spin_lock_init(&priv->lock);
 
 	dev_info(&pdev->dev, "reserved resource region %pR\n", res);
 
@@ -347,8 +342,7 @@ static int cs5535_gpio_probe(struct platform_device *pdev)
 				mask_orig, mask);
 
 	/* finally, register with the generic GPIO API */
-	return devm_gpiochip_add_data(&pdev->dev, &cs5535_gpio_chip.chip,
-				      &cs5535_gpio_chip);
+	return devm_gpiochip_add_data(&pdev->dev, gc, priv);
 }
 
 static struct platform_driver cs5535_gpio_driver = {
-- 
2.53.0


             reply	other threads:[~2026-03-13  0:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-13  0:12 Rosen Penev [this message]
2026-03-16  9:11 ` [PATCH] gpio: cs5535: use dynamically allocated priv struct Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260313001209.117823-1-rosenp@gmail.com \
    --to=rosenp@gmail.com \
    --cc=brgl@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox