diff mbox series

[PATCH/RFC] soc: bcm2835: Make !RASPBERRYPI_FIRMWARE dummies return failure

Message ID 1523178315-30562-1-git-send-email-geert@linux-m68k.org
State New
Headers show
Series [PATCH/RFC] soc: bcm2835: Make !RASPBERRYPI_FIRMWARE dummies return failure | expand

Commit Message

Geert Uytterhoeven April 8, 2018, 9:05 a.m. UTC
If CONFIG_RASPBERRYPI_FIRMWARE=n:

    drivers/gpio/gpio-raspberrypi-exp.c: In function ‘rpi_exp_gpio_get_polarity’:
    drivers/gpio/gpio-raspberrypi-exp.c:71: warning: ‘get.polarity’ is used uninitialized in this function
    drivers/gpio/gpio-raspberrypi-exp.c: In function ‘rpi_exp_gpio_get_direction’:
    drivers/gpio/gpio-raspberrypi-exp.c:150: warning: ‘get.direction’ is used uninitialized in this function

The dummy firmware interface functions return 0, which means success,
causing subsequent code to make use of the never initialized output
parameter.

Fix this by making the dummy functions return an error code (-ENOSYS)
instead.

Note that this assumes the firmware always fills in the requested data
in the CONFIG_RASPBERRYPI_FIRMWARE=y case.

Fixes: d45f1a563b92dac7 ("staging: vc04_services: fix up rpi firmware functions")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
Should get.polarity resp. get.direction be preinitialized instead,
like is done for get.state?

static int rpi_exp_gpio_get(struct gpio_chip *gc, unsigned int off)
{
        ...
        get.state = 0;          /* storage for returned value */

        ret = rpi_firmware_property(gpio->fw, RPI_FIRMWARE_GET_GPIO_STATE,
                                         &get, sizeof(get));
        ...
}

This would avoid returning uninitialized data if the firmware did not
fill in the requested data.
---
 include/soc/bcm2835/raspberrypi-firmware.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Stefan Wahren April 8, 2018, 11:28 a.m. UTC | #1
Hi Geert,

[add Phil]

> Geert Uytterhoeven <geert@linux-m68k.org> hat am 8. April 2018 um 11:05 geschrieben:
> 
> 
> If CONFIG_RASPBERRYPI_FIRMWARE=n:
> 
>     drivers/gpio/gpio-raspberrypi-exp.c: In function ‘rpi_exp_gpio_get_polarity’:
>     drivers/gpio/gpio-raspberrypi-exp.c:71: warning: ‘get.polarity’ is used uninitialized in this function
>     drivers/gpio/gpio-raspberrypi-exp.c: In function ‘rpi_exp_gpio_get_direction’:
>     drivers/gpio/gpio-raspberrypi-exp.c:150: warning: ‘get.direction’ is used uninitialized in this function
> 
> The dummy firmware interface functions return 0, which means success,
> causing subsequent code to make use of the never initialized output
> parameter.

i think this is more theoritical, because we need to get rpi_firmware first and in this case it's NULL.

> 
> Fix this by making the dummy functions return an error code (-ENOSYS)
> instead.

Anyway i'm okay with the change.

> 
> Note that this assumes the firmware always fills in the requested data
> in the CONFIG_RASPBERRYPI_FIRMWARE=y case.

Unfortunately i don't know.

> 
> Fixes: d45f1a563b92dac7 ("staging: vc04_services: fix up rpi firmware functions")
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> ---
> Should get.polarity resp. get.direction be preinitialized instead,
> like is done for get.state?
> 
> static int rpi_exp_gpio_get(struct gpio_chip *gc, unsigned int off)
> {
>         ...
>         get.state = 0;          /* storage for returned value */
> 
>         ret = rpi_firmware_property(gpio->fw, RPI_FIRMWARE_GET_GPIO_STATE,
>                                          &get, sizeof(get));
>         ...
> }
> 
> This would avoid returning uninitialized data if the firmware did not
> fill in the requested data.
> ---
>  include/soc/bcm2835/raspberrypi-firmware.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/include/soc/bcm2835/raspberrypi-firmware.h b/include/soc/bcm2835/raspberrypi-firmware.h
> index 50df5b28d2c9df6e..8ee8991aa099af3a 100644
> --- a/include/soc/bcm2835/raspberrypi-firmware.h
> +++ b/include/soc/bcm2835/raspberrypi-firmware.h
> @@ -143,13 +143,13 @@ struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node);
>  static inline int rpi_firmware_property(struct rpi_firmware *fw, u32 tag,
>  					void *data, size_t len)
>  {
> -	return 0;
> +	return -ENOSYS;
>  }
>  
>  static inline int rpi_firmware_property_list(struct rpi_firmware *fw,
>  					     void *data, size_t tag_size)
>  {
> -	return 0;
> +	return -ENOSYS;
>  }
>  
>  static inline struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node)
> -- 
> 2.7.4
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Phil Elwell April 9, 2018, 1:26 p.m. UTC | #2
On 08/04/2018 12:28, Stefan Wahren wrote:
> Hi Geert,
> 
> [add Phil]
> 
>> Geert Uytterhoeven <geert@linux-m68k.org> hat am 8. April 2018 um 11:05 geschrieben:
>>
>>
>> If CONFIG_RASPBERRYPI_FIRMWARE=n:
>>
>>     drivers/gpio/gpio-raspberrypi-exp.c: In function ‘rpi_exp_gpio_get_polarity’:
>>     drivers/gpio/gpio-raspberrypi-exp.c:71: warning: ‘get.polarity’ is used uninitialized in this function
>>     drivers/gpio/gpio-raspberrypi-exp.c: In function ‘rpi_exp_gpio_get_direction’:
>>     drivers/gpio/gpio-raspberrypi-exp.c:150: warning: ‘get.direction’ is used uninitialized in this function
>>
>> The dummy firmware interface functions return 0, which means success,
>> causing subsequent code to make use of the never initialized output
>> parameter.
> 
> i think this is more theoritical, because we need to get rpi_firmware first and in this case it's NULL.
> 
>>
>> Fix this by making the dummy functions return an error code (-ENOSYS)
>> instead.
> 
> Anyway i'm okay with the change.
> 
>>
>> Note that this assumes the firmware always fills in the requested data
>> in the CONFIG_RASPBERRYPI_FIRMWARE=y case.
> 
> Unfortunately i don't know.

The firmware overwrites the request code with an error return value. If this appears
and has an error value of zero (RPI_FIRMWARE_STATUS_SUCCESS) then the firmware has
written any expected fields.

> 
>>
>> Fixes: d45f1a563b92dac7 ("staging: vc04_services: fix up rpi firmware functions")
>> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
>> ---
>> Should get.polarity resp. get.direction be preinitialized instead,
>> like is done for get.state?
>>
>> static int rpi_exp_gpio_get(struct gpio_chip *gc, unsigned int off)
>> {
>>         ...
>>         get.state = 0;          /* storage for returned value */
>>
>>         ret = rpi_firmware_property(gpio->fw, RPI_FIRMWARE_GET_GPIO_STATE,
>>                                          &get, sizeof(get));
>>         ...
>> }
>>
>> This would avoid returning uninitialized data if the firmware did not
>> fill in the requested data.
>> ---
>>  include/soc/bcm2835/raspberrypi-firmware.h | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/include/soc/bcm2835/raspberrypi-firmware.h b/include/soc/bcm2835/raspberrypi-firmware.h
>> index 50df5b28d2c9df6e..8ee8991aa099af3a 100644
>> --- a/include/soc/bcm2835/raspberrypi-firmware.h
>> +++ b/include/soc/bcm2835/raspberrypi-firmware.h
>> @@ -143,13 +143,13 @@ struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node);
>>  static inline int rpi_firmware_property(struct rpi_firmware *fw, u32 tag,
>>  					void *data, size_t len)
>>  {
>> -	return 0;
>> +	return -ENOSYS;
>>  }
>>  
>>  static inline int rpi_firmware_property_list(struct rpi_firmware *fw,
>>  					     void *data, size_t tag_size)
>>  {
>> -	return 0;
>> +	return -ENOSYS;
>>  }
>>  
>>  static inline struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node)
>> -- 
>> 2.7.4
>>
>>
>> _______________________________________________
>> linux-arm-kernel mailing list
>> linux-arm-kernel@lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Geert Uytterhoeven April 9, 2018, 1:29 p.m. UTC | #3
Hi Stefan,

On Sun, Apr 8, 2018 at 1:28 PM, Stefan Wahren <stefan.wahren@i2se.com> wrote:
>> Geert Uytterhoeven <geert@linux-m68k.org> hat am 8. April 2018 um 11:05 geschrieben:
>> If CONFIG_RASPBERRYPI_FIRMWARE=n:
>>
>>     drivers/gpio/gpio-raspberrypi-exp.c: In function ‘rpi_exp_gpio_get_polarity’:
>>     drivers/gpio/gpio-raspberrypi-exp.c:71: warning: ‘get.polarity’ is used uninitialized in this function
>>     drivers/gpio/gpio-raspberrypi-exp.c: In function ‘rpi_exp_gpio_get_direction’:
>>     drivers/gpio/gpio-raspberrypi-exp.c:150: warning: ‘get.direction’ is used uninitialized in this function
>>
>> The dummy firmware interface functions return 0, which means success,
>> causing subsequent code to make use of the never initialized output
>> parameter.
>
> i think this is more theoritical, because we need to get rpi_firmware first and in this case it's NULL.

Sure, I just want to get rid of the ugly warnings when compile-testing.
Most dummy functions for other subsystems return error codes.

>> Fix this by making the dummy functions return an error code (-ENOSYS)
>> instead.
>
> Anyway i'm okay with the change.

OK, thanks!

Gr{oetje,eeting}s,

                        Geert
Eric Anholt April 9, 2018, 7:39 p.m. UTC | #4
Geert Uytterhoeven <geert@linux-m68k.org> writes:

> If CONFIG_RASPBERRYPI_FIRMWARE=n:
>
>     drivers/gpio/gpio-raspberrypi-exp.c: In function ‘rpi_exp_gpio_get_polarity’:
>     drivers/gpio/gpio-raspberrypi-exp.c:71: warning: ‘get.polarity’ is used uninitialized in this function
>     drivers/gpio/gpio-raspberrypi-exp.c: In function ‘rpi_exp_gpio_get_direction’:
>     drivers/gpio/gpio-raspberrypi-exp.c:150: warning: ‘get.direction’ is used uninitialized in this function
>
> The dummy firmware interface functions return 0, which means success,
> causing subsequent code to make use of the never initialized output
> parameter.
>
> Fix this by making the dummy functions return an error code (-ENOSYS)
> instead.
>
> Note that this assumes the firmware always fills in the requested data
> in the CONFIG_RASPBERRYPI_FIRMWARE=y case.
>
> Fixes: d45f1a563b92dac7 ("staging: vc04_services: fix up rpi firmware functions")
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>

You should definitely not be calling these if rpi_firmware_get() failed,
so this seems like a good solution.

Reviewed-by: Eric Anholt <eric@anholt.net>
Florian Fainelli April 13, 2018, 10:11 p.m. UTC | #5
On 04/08/2018 02:05 AM, Geert Uytterhoeven wrote:
> If CONFIG_RASPBERRYPI_FIRMWARE=n:
> 
>     drivers/gpio/gpio-raspberrypi-exp.c: In function ‘rpi_exp_gpio_get_polarity’:
>     drivers/gpio/gpio-raspberrypi-exp.c:71: warning: ‘get.polarity’ is used uninitialized in this function
>     drivers/gpio/gpio-raspberrypi-exp.c: In function ‘rpi_exp_gpio_get_direction’:
>     drivers/gpio/gpio-raspberrypi-exp.c:150: warning: ‘get.direction’ is used uninitialized in this function
> 
> The dummy firmware interface functions return 0, which means success,
> causing subsequent code to make use of the never initialized output
> parameter.
> 
> Fix this by making the dummy functions return an error code (-ENOSYS)
> instead.
> 
> Note that this assumes the firmware always fills in the requested data
> in the CONFIG_RASPBERRYPI_FIRMWARE=y case.
> 
> Fixes: d45f1a563b92dac7 ("staging: vc04_services: fix up rpi firmware functions")
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>

Applied, thanks Geert!
diff mbox series

Patch

diff --git a/include/soc/bcm2835/raspberrypi-firmware.h b/include/soc/bcm2835/raspberrypi-firmware.h
index 50df5b28d2c9df6e..8ee8991aa099af3a 100644
--- a/include/soc/bcm2835/raspberrypi-firmware.h
+++ b/include/soc/bcm2835/raspberrypi-firmware.h
@@ -143,13 +143,13 @@  struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node);
 static inline int rpi_firmware_property(struct rpi_firmware *fw, u32 tag,
 					void *data, size_t len)
 {
-	return 0;
+	return -ENOSYS;
 }
 
 static inline int rpi_firmware_property_list(struct rpi_firmware *fw,
 					     void *data, size_t tag_size)
 {
-	return 0;
+	return -ENOSYS;
 }
 
 static inline struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node)