diff options
| author | Rosen Penev <rosenp@gmail.com> | 2026-03-13 03:12:09 +0300 |
|---|---|---|
| committer | Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com> | 2026-03-16 12:11:02 +0300 |
| commit | a6e53d05ab849779d55ca985566a1da7f22435b9 (patch) | |
| tree | b03c67ff7c9c44fd02c08c0f8792cb142fbca869 | |
| parent | 3518fd4c780d4fa4c0e2cedd95c0f8bc5d8b457f (diff) | |
| download | linux-a6e53d05ab849779d55ca985566a1da7f22435b9.tar.xz | |
gpio: cs5535: use dynamically allocated priv struct
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>
Link: https://patch.msgid.link/20260313001209.117823-1-rosenp@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
| -rw-r--r-- | drivers/gpio/gpio-cs5535.c | 48 |
1 files 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 = { |
