[PATCH] gpio: cs5535: use dynamically allocated priv struct
From: Rosen Penev
Date: Thu Mar 12 2026 - 20:13:08 EST
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@xxxxxxxxx>
---
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