Skip to content

Commit d036ae4

Browse files
author
Bartosz Golaszewski
committed
gpio: grgpio: use a helper variable to store the address of ofdev->dev
Instead of dereferencing the platform device pointer repeatedly, just store its address in a helper variable. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 537ec28 commit d036ae4

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

drivers/gpio/gpio-grgpio.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ static const struct irq_domain_ops grgpio_irq_domain_ops = {
328328
static int grgpio_probe(struct platform_device *ofdev)
329329
{
330330
struct device_node *np = ofdev->dev.of_node;
331+
struct device *dev = &ofdev->dev;
331332
void __iomem *regs;
332333
struct gpio_chip *gc;
333334
struct grgpio_priv *priv;
@@ -337,7 +338,7 @@ static int grgpio_probe(struct platform_device *ofdev)
337338
int size;
338339
int i;
339340

340-
priv = devm_kzalloc(&ofdev->dev, sizeof(*priv), GFP_KERNEL);
341+
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
341342
if (!priv)
342343
return -ENOMEM;
343344

@@ -346,28 +347,28 @@ static int grgpio_probe(struct platform_device *ofdev)
346347
return PTR_ERR(regs);
347348

348349
gc = &priv->gc;
349-
err = bgpio_init(gc, &ofdev->dev, 4, regs + GRGPIO_DATA,
350+
err = bgpio_init(gc, dev, 4, regs + GRGPIO_DATA,
350351
regs + GRGPIO_OUTPUT, NULL, regs + GRGPIO_DIR, NULL,
351352
BGPIOF_BIG_ENDIAN_BYTE_ORDER);
352353
if (err) {
353-
dev_err(&ofdev->dev, "bgpio_init() failed\n");
354+
dev_err(dev, "bgpio_init() failed\n");
354355
return err;
355356
}
356357

357358
priv->regs = regs;
358359
priv->imask = gc->read_reg(regs + GRGPIO_IMASK);
359-
priv->dev = &ofdev->dev;
360+
priv->dev = dev;
360361

361362
gc->owner = THIS_MODULE;
362363
gc->to_irq = grgpio_to_irq;
363-
gc->label = devm_kasprintf(&ofdev->dev, GFP_KERNEL, "%pOF", np);
364+
gc->label = devm_kasprintf(dev, GFP_KERNEL, "%pOF", np);
364365
gc->base = -1;
365366

366367
err = of_property_read_u32(np, "nbits", &prop);
367368
if (err || prop <= 0 || prop > GRGPIO_MAX_NGPIO) {
368369
gc->ngpio = GRGPIO_MAX_NGPIO;
369-
dev_dbg(&ofdev->dev,
370-
"No or invalid nbits property: assume %d\n", gc->ngpio);
370+
dev_dbg(dev, "No or invalid nbits property: assume %d\n",
371+
gc->ngpio);
371372
} else {
372373
gc->ngpio = prop;
373374
}
@@ -379,7 +380,7 @@ static int grgpio_probe(struct platform_device *ofdev)
379380
irqmap = (s32 *)of_get_property(np, "irqmap", &size);
380381
if (irqmap) {
381382
if (size < gc->ngpio) {
382-
dev_err(&ofdev->dev,
383+
dev_err(dev,
383384
"irqmap shorter than ngpio (%d < %d)\n",
384385
size, gc->ngpio);
385386
return -EINVAL;
@@ -389,7 +390,7 @@ static int grgpio_probe(struct platform_device *ofdev)
389390
&grgpio_irq_domain_ops,
390391
priv);
391392
if (!priv->domain) {
392-
dev_err(&ofdev->dev, "Could not add irq domain\n");
393+
dev_err(dev, "Could not add irq domain\n");
393394
return -EINVAL;
394395
}
395396

@@ -419,13 +420,13 @@ static int grgpio_probe(struct platform_device *ofdev)
419420

420421
err = gpiochip_add_data(gc, priv);
421422
if (err) {
422-
dev_err(&ofdev->dev, "Could not add gpiochip\n");
423+
dev_err(dev, "Could not add gpiochip\n");
423424
if (priv->domain)
424425
irq_domain_remove(priv->domain);
425426
return err;
426427
}
427428

428-
dev_info(&ofdev->dev, "regs=0x%p, base=%d, ngpio=%d, irqs=%s\n",
429+
dev_info(dev, "regs=0x%p, base=%d, ngpio=%d, irqs=%s\n",
429430
priv->regs, gc->base, gc->ngpio, priv->domain ? "on" : "off");
430431

431432
return 0;

0 commit comments

Comments
 (0)