Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Rosen Penev and committed by
Bartosz Golaszewski
a6e53d05 3518fd4c

+21 -27
+21 -27
drivers/gpio/gpio-cs5535.c
··· 39 39 module_param_named(mask, mask, ulong, 0444); 40 40 MODULE_PARM_DESC(mask, "GPIO channel mask."); 41 41 42 - /* 43 - * FIXME: convert this singleton driver to use the state container 44 - * design pattern, see Documentation/driver-api/driver-model/design-patterns.rst 45 - */ 46 42 static struct cs5535_gpio_chip { 47 43 struct gpio_chip chip; 48 44 resource_size_t base; ··· 281 285 "GPIO28", NULL, NULL, NULL, 282 286 }; 283 287 284 - static struct cs5535_gpio_chip cs5535_gpio_chip = { 285 - .chip = { 286 - .owner = THIS_MODULE, 287 - .label = DRV_NAME, 288 - 289 - .base = 0, 290 - .ngpio = 32, 291 - .names = cs5535_gpio_names, 292 - .request = chip_gpio_request, 293 - 294 - .get = chip_gpio_get, 295 - .set = chip_gpio_set, 296 - 297 - .direction_input = chip_direction_input, 298 - .direction_output = chip_direction_output, 299 - }, 300 - }; 301 - 302 288 static int cs5535_gpio_probe(struct platform_device *pdev) 303 289 { 290 + struct cs5535_gpio_chip *priv; 291 + struct gpio_chip *gc; 304 292 struct resource *res; 305 293 int err = -EIO; 306 294 ulong mask_orig = mask; 295 + 296 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 297 + if (!priv) 298 + return -ENOMEM; 299 + 300 + gc = &priv->chip; 301 + gc->owner = THIS_MODULE; 302 + gc->label = DRV_NAME; 303 + gc->ngpio = 32; 304 + gc->names = cs5535_gpio_names; 305 + gc->request = chip_gpio_request; 306 + gc->get = chip_gpio_get; 307 + gc->set = chip_gpio_set; 308 + gc->direction_input = chip_direction_input; 309 + gc->direction_output = chip_direction_output; 307 310 308 311 /* There are two ways to get the GPIO base address; one is by 309 312 * fetching it from MSR_LBAR_GPIO, the other is by reading the ··· 324 329 } 325 330 326 331 /* set up the driver-specific struct */ 327 - cs5535_gpio_chip.base = res->start; 328 - cs5535_gpio_chip.pdev = pdev; 329 - spin_lock_init(&cs5535_gpio_chip.lock); 332 + priv->base = res->start; 333 + priv->pdev = pdev; 334 + spin_lock_init(&priv->lock); 330 335 331 336 dev_info(&pdev->dev, "reserved resource region %pR\n", res); 332 337 ··· 342 347 mask_orig, mask); 343 348 344 349 /* finally, register with the generic GPIO API */ 345 - return devm_gpiochip_add_data(&pdev->dev, &cs5535_gpio_chip.chip, 346 - &cs5535_gpio_chip); 350 + return devm_gpiochip_add_data(&pdev->dev, gc, priv); 347 351 } 348 352 349 353 static struct platform_driver cs5535_gpio_driver = {