* [bug report] pinctrl: Add STM32 MCUs support
@ 2017-05-04 6:54 Dan Carpenter
2017-05-04 7:58 ` Alexandre Torgue
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2017-05-04 6:54 UTC (permalink / raw)
To: mcoquelin.stm32; +Cc: linux-gpio, Alexandre TORGUE
Hello Maxime Coquelin,
The patch aceb16dc2da5: "pinctrl: Add STM32 MCUs support" from Jan
14, 2016, leads to the following static checker warning:
drivers/pinctrl/stm32/pinctrl-stm32.c:801 stm32_pconf_parse_conf()
error: NULL dereference inside function.
drivers/pinctrl/stm32/pinctrl-stm32.c
615 static int stm32_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
616 struct pinctrl_gpio_range *range, unsigned gpio,
617 bool input)
618 {
619 struct stm32_gpio_bank *bank = gpiochip_get_data(range->gc);
^^^^^^^^^
This warning only showed up recently because we changed this line to a
dereference, but it was never valid to pass a NULL range.
620 int pin = stm32_gpio_pin(gpio);
621
622 stm32_pmx_set_mode(bank, pin, !input, 0);
623
624 return 0;
625 }
[ snip ]
768 static int stm32_pconf_parse_conf(struct pinctrl_dev *pctldev,
769 unsigned int pin, enum pin_config_param param,
770 enum pin_config_param arg)
771 {
772 struct pinctrl_gpio_range *range;
773 struct stm32_gpio_bank *bank;
774 int offset, ret = 0;
775
776 range = pinctrl_find_gpio_range_from_pin(pctldev, pin);
777 bank = gpiochip_get_data(range->gc);
778 offset = stm32_gpio_pin(pin);
779
780 switch (param) {
781 case PIN_CONFIG_DRIVE_PUSH_PULL:
782 stm32_pconf_set_driving(bank, offset, 0);
783 break;
784 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
785 stm32_pconf_set_driving(bank, offset, 1);
786 break;
787 case PIN_CONFIG_SLEW_RATE:
788 stm32_pconf_set_speed(bank, offset, arg);
789 break;
790 case PIN_CONFIG_BIAS_DISABLE:
791 stm32_pconf_set_bias(bank, offset, 0);
792 break;
793 case PIN_CONFIG_BIAS_PULL_UP:
794 stm32_pconf_set_bias(bank, offset, 1);
795 break;
796 case PIN_CONFIG_BIAS_PULL_DOWN:
797 stm32_pconf_set_bias(bank, offset, 2);
798 break;
799 case PIN_CONFIG_OUTPUT:
800 __stm32_gpio_set(bank, offset, arg);
801 ret = stm32_pmx_gpio_set_direction(pctldev, NULL, pin, false);
^^^^
A NULL range will Oops.
802 break;
803 default:
804 ret = -EINVAL;
805 }
806
807 return ret;
808 }
regards,
dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [bug report] pinctrl: Add STM32 MCUs support
2017-05-04 6:54 [bug report] pinctrl: Add STM32 MCUs support Dan Carpenter
@ 2017-05-04 7:58 ` Alexandre Torgue
0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Torgue @ 2017-05-04 7:58 UTC (permalink / raw)
To: Dan Carpenter, mcoquelin.stm32; +Cc: linux-gpio
Hi Dan,
On 05/04/2017 08:54 AM, Dan Carpenter wrote:
> Hello Maxime Coquelin,
>
> The patch aceb16dc2da5: "pinctrl: Add STM32 MCUs support" from Jan
> 14, 2016, leads to the following static checker warning:
>
> drivers/pinctrl/stm32/pinctrl-stm32.c:801 stm32_pconf_parse_conf()
> error: NULL dereference inside function.
>
> drivers/pinctrl/stm32/pinctrl-stm32.c
> 615 static int stm32_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
> 616 struct pinctrl_gpio_range *range, unsigned gpio,
> 617 bool input)
> 618 {
> 619 struct stm32_gpio_bank *bank = gpiochip_get_data(range->gc);
> ^^^^^^^^^
> This warning only showed up recently because we changed this line to a
> dereference, but it was never valid to pass a NULL range.
>
> 620 int pin = stm32_gpio_pin(gpio);
> 621
> 622 stm32_pmx_set_mode(bank, pin, !input, 0);
> 623
> 624 return 0;
> 625 }
>
> [ snip ]
>
> 768 static int stm32_pconf_parse_conf(struct pinctrl_dev *pctldev,
> 769 unsigned int pin, enum pin_config_param param,
> 770 enum pin_config_param arg)
> 771 {
> 772 struct pinctrl_gpio_range *range;
> 773 struct stm32_gpio_bank *bank;
> 774 int offset, ret = 0;
> 775
> 776 range = pinctrl_find_gpio_range_from_pin(pctldev, pin);
> 777 bank = gpiochip_get_data(range->gc);
> 778 offset = stm32_gpio_pin(pin);
> 779
> 780 switch (param) {
> 781 case PIN_CONFIG_DRIVE_PUSH_PULL:
> 782 stm32_pconf_set_driving(bank, offset, 0);
> 783 break;
> 784 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
> 785 stm32_pconf_set_driving(bank, offset, 1);
> 786 break;
> 787 case PIN_CONFIG_SLEW_RATE:
> 788 stm32_pconf_set_speed(bank, offset, arg);
> 789 break;
> 790 case PIN_CONFIG_BIAS_DISABLE:
> 791 stm32_pconf_set_bias(bank, offset, 0);
> 792 break;
> 793 case PIN_CONFIG_BIAS_PULL_UP:
> 794 stm32_pconf_set_bias(bank, offset, 1);
> 795 break;
> 796 case PIN_CONFIG_BIAS_PULL_DOWN:
> 797 stm32_pconf_set_bias(bank, offset, 2);
> 798 break;
> 799 case PIN_CONFIG_OUTPUT:
> 800 __stm32_gpio_set(bank, offset, arg);
> 801 ret = stm32_pmx_gpio_set_direction(pctldev, NULL, pin, false);
> ^^^^
> A NULL range will Oops.
Yes, I agree. I will send a fix.
regards
Alex
>
> 802 break;
> 803 default:
> 804 ret = -EINVAL;
> 805 }
> 806
> 807 return ret;
> 808 }
>
> regards,
> dan carpenter
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-05-04 7:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-04 6:54 [bug report] pinctrl: Add STM32 MCUs support Dan Carpenter
2017-05-04 7:58 ` Alexandre Torgue
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).