Skip to content

Commit 25a853d

Browse files
firstbreadlinusw
authored andcommitted
Fix inconsistent spinlock of AMD GPIO driver which can be
recognized by static analysis tool smatch. Declare constant Variables with Sparse's suggestion. Signed-off-by: Ken Xue <Ken.Xue@amd.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent d480239 commit 25a853d

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

drivers/pinctrl/pinctrl-amd.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include <linux/interrupt.h>
3030
#include <linux/list.h>
3131
#include <linux/bitops.h>
32-
#include <linux/pinctrl/pinctrl.h>
3332
#include <linux/pinctrl/pinconf.h>
3433
#include <linux/pinctrl/pinconf-generic.h>
3534

@@ -119,8 +118,9 @@ static void amd_gpio_set_value(struct gpio_chip *gc, unsigned offset, int value)
119118
static int amd_gpio_set_debounce(struct gpio_chip *gc, unsigned offset,
120119
unsigned debounce)
121120
{
122-
u32 pin_reg;
123121
u32 time;
122+
u32 pin_reg;
123+
int ret = 0;
124124
unsigned long flags;
125125
struct amd_gpio *gpio_dev = to_amd_gpio(gc);
126126

@@ -166,7 +166,7 @@ static int amd_gpio_set_debounce(struct gpio_chip *gc, unsigned offset,
166166
pin_reg |= BIT(DB_TMR_LARGE_OFF);
167167
} else {
168168
pin_reg &= ~DB_CNTRl_MASK;
169-
return -EINVAL;
169+
ret = -EINVAL;
170170
}
171171
} else {
172172
pin_reg &= ~BIT(DB_TMR_OUT_UNIT_OFF);
@@ -177,7 +177,7 @@ static int amd_gpio_set_debounce(struct gpio_chip *gc, unsigned offset,
177177
writel(pin_reg, gpio_dev->base + offset * 4);
178178
spin_unlock_irqrestore(&gpio_dev->lock, flags);
179179

180-
return 0;
180+
return ret;
181181
}
182182

183183
#ifdef CONFIG_DEBUG_FS
@@ -463,14 +463,12 @@ static int amd_gpio_irq_set_type(struct irq_data *d, unsigned int type)
463463
default:
464464
dev_err(&gpio_dev->pdev->dev, "Invalid type value\n");
465465
ret = -EINVAL;
466-
goto exit;
467466
}
468467

469468
pin_reg |= CLR_INTR_STAT << INTERRUPT_STS_OFF;
470469
writel(pin_reg, gpio_dev->base + (d->hwirq)*4);
471470
spin_unlock_irqrestore(&gpio_dev->lock, flags);
472471

473-
exit:
474472
return ret;
475473
}
476474

@@ -635,8 +633,9 @@ static int amd_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
635633
unsigned long *configs, unsigned num_configs)
636634
{
637635
int i;
638-
u32 pin_reg;
639636
u32 arg;
637+
int ret = 0;
638+
u32 pin_reg;
640639
unsigned long flags;
641640
enum pin_config_param param;
642641
struct amd_gpio *gpio_dev = pinctrl_dev_get_drvdata(pctldev);
@@ -675,14 +674,14 @@ static int amd_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
675674
default:
676675
dev_err(&gpio_dev->pdev->dev,
677676
"Invalid config param %04x\n", param);
678-
return -ENOTSUPP;
677+
ret = -ENOTSUPP;
679678
}
680679

681680
writel(pin_reg, gpio_dev->base + pin*4);
682681
}
683682
spin_unlock_irqrestore(&gpio_dev->lock, flags);
684683

685-
return 0;
684+
return ret;
686685
}
687686

688687
static int amd_pinconf_group_get(struct pinctrl_dev *pctldev,
@@ -739,7 +738,7 @@ static struct pinctrl_desc amd_pinctrl_desc = {
739738
static int amd_gpio_probe(struct platform_device *pdev)
740739
{
741740
int ret = 0;
742-
u32 irq_base;
741+
int irq_base;
743742
struct resource *res;
744743
struct amd_gpio *gpio_dev;
745744

drivers/pinctrl/pinctrl-amd.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,13 @@ static const struct pinctrl_pin_desc kerncz_pins[] = {
217217
PINCTRL_PIN(177, "GPIO_177"),
218218
};
219219

220-
const unsigned i2c0_pins[] = {145, 146};
221-
const unsigned i2c1_pins[] = {147, 148};
222-
const unsigned i2c2_pins[] = {113, 114};
223-
const unsigned i2c3_pins[] = {19, 20};
220+
static const unsigned i2c0_pins[] = {145, 146};
221+
static const unsigned i2c1_pins[] = {147, 148};
222+
static const unsigned i2c2_pins[] = {113, 114};
223+
static const unsigned i2c3_pins[] = {19, 20};
224224

225-
const unsigned uart0_pins[] = {135, 136, 137, 138, 139};
226-
const unsigned uart1_pins[] = {140, 141, 142, 143, 144};
225+
static const unsigned uart0_pins[] = {135, 136, 137, 138, 139};
226+
static const unsigned uart1_pins[] = {140, 141, 142, 143, 144};
227227

228228
static const struct amd_pingroup kerncz_groups[] = {
229229
{

0 commit comments

Comments
 (0)