Commit 4ed0d0b0 authored by Bartosz Golaszewski's avatar Bartosz Golaszewski Committed by cuiyudong
Browse files

gpio: grgpio: use a helper variable to store the address of ofdev->dev

stable inclusion
from stable-v6.6.66
commit 9cc1a6ce157d028023f172aa9608e045fef1b96b
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBLUBO

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=9cc1a6ce157d028023f172aa9608e045fef1b96b

--------------------------------

[ Upstream commit d036ae41cebdfae92666024163c109b8fef516fa ]

Instead of dereferencing the platform device pointer repeatedly, just
store its address in a helper variable.

Link: https://lore.kernel.org/r/20241015131832.44678-3-brgl@bgdev.pl


Signed-off-by: default avatarBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Stable-dep-of: 050b23d081da ("gpio: grgpio: Add NULL check in grgpio_probe")
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Conflicts:
drivers/gpio/gpio-grgpio.c
Signed-off-by: default avatarcuiyudong <cuiyudong@kylinos.cn>
parent 07519775
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -328,6 +328,7 @@ static const struct irq_domain_ops grgpio_irq_domain_ops = {
static int grgpio_probe(struct platform_device *ofdev)
{
	struct device_node *np = ofdev->dev.of_node;
	struct device *dev = &ofdev->dev;
	void  __iomem *regs;
	struct gpio_chip *gc;
	struct grgpio_priv *priv;
@@ -337,7 +338,7 @@ static int grgpio_probe(struct platform_device *ofdev)
	int size;
	int i;

	priv = devm_kzalloc(&ofdev->dev, sizeof(*priv), GFP_KERNEL);
	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
	if (!priv)
		return -ENOMEM;

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

	gc = &priv->gc;
	err = bgpio_init(gc, &ofdev->dev, 4, regs + GRGPIO_DATA,
	err = bgpio_init(gc, dev, 4, regs + GRGPIO_DATA,
			 regs + GRGPIO_OUTPUT, NULL, regs + GRGPIO_DIR, NULL,
			 BGPIOF_BIG_ENDIAN_BYTE_ORDER);
	if (err) {
		dev_err(&ofdev->dev, "bgpio_init() failed\n");
		dev_err(dev, "bgpio_init() failed\n");
		return err;
	}

	priv->regs = regs;
	priv->imask = gc->read_reg(regs + GRGPIO_IMASK);
	priv->dev = &ofdev->dev;
	priv->dev = dev;

	gc->owner = THIS_MODULE;
	gc->to_irq = grgpio_to_irq;
	gc->label = devm_kasprintf(&ofdev->dev, GFP_KERNEL, "%pOF", np);
	gc->label = devm_kasprintf(dev, GFP_KERNEL, "%pOF", np);
	if (!gc->label)
		return -ENOMEM;

@@ -369,8 +370,8 @@ static int grgpio_probe(struct platform_device *ofdev)
	err = of_property_read_u32(np, "nbits", &prop);
	if (err || prop <= 0 || prop > GRGPIO_MAX_NGPIO) {
		gc->ngpio = GRGPIO_MAX_NGPIO;
		dev_dbg(&ofdev->dev,
			"No or invalid nbits property: assume %d\n", gc->ngpio);
		dev_dbg(dev, "No or invalid nbits property: assume %d\n",
			gc->ngpio);
	} else {
		gc->ngpio = prop;
	}
@@ -382,7 +383,7 @@ static int grgpio_probe(struct platform_device *ofdev)
	irqmap = (s32 *)of_get_property(np, "irqmap", &size);
	if (irqmap) {
		if (size < gc->ngpio) {
			dev_err(&ofdev->dev,
			dev_err(dev,
				"irqmap shorter than ngpio (%d < %d)\n",
				size, gc->ngpio);
			return -EINVAL;
@@ -392,7 +393,7 @@ static int grgpio_probe(struct platform_device *ofdev)
						     &grgpio_irq_domain_ops,
						     priv);
		if (!priv->domain) {
			dev_err(&ofdev->dev, "Could not add irq domain\n");
			dev_err(dev, "Could not add irq domain\n");
			return -EINVAL;
		}

@@ -422,13 +423,13 @@ static int grgpio_probe(struct platform_device *ofdev)

	err = gpiochip_add_data(gc, priv);
	if (err) {
		dev_err(&ofdev->dev, "Could not add gpiochip\n");
		dev_err(dev, "Could not add gpiochip\n");
		if (priv->domain)
			irq_domain_remove(priv->domain);
		return err;
	}

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

	return 0;