Fix static analyser and compiler warnings in int3472
Sakari Ailus
maintainercover Fix static analyser and compiler warnings in int3472
Hi folks,
These two patches address smatch and compiler warnings in int3472.
Just compile tested for now. :-)
Sakari Ailus (2):
platform/x86: int3472: Address Coccinelle warning on an error print platform/x86: int3472: Fix uninitialised variable warning
drivers/platform/x86/intel/int3472/discrete.c | 21 +++++++++---------- drivers/platform/x86/intel/int3472/tps68470.c | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-)
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH 1/2 platform/x86: int3472: Address Coccinelle warning on an error print
Fix the following Coccinelle warning:
./tps68470.c:164:58-65: WARNING: Consider using %pe to print PTR_ERR()
by using %pe specifier for printing an error code.
--- drivers/platform/x86/intel/int3472/tps68470.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/intel/int3472/tps68470.c +1 -1
@@ -161,7 +161,7 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client) regmap =devm_regmap_init_i2c (client, &tps68470_regmap_config);if (IS_ERR (regmap)) { -dev_err (&client->dev,"Failed to create regmap: %ld\n" ,PTR_ERR (regmap)); +dev_err (&client->dev,"Failed to create regmap: %pe\n" , regmap);return PTR_ERR (regmap); }
Signature · 1 line
2.47.3
Re: [PATCH 1/2] platform/x86: int3472: Address Coccinelle warning on an error print
Quoted 3 lines · Sakari Ailus
Fix the following Coccinelle warning:
./tps68470.c:164:58-65: WARNING: Consider using %pe to print
PTR_ERR()
It seems coccinelle scripts too employ scare tactics. :-/
The change is fine,
Quoted 21 lines
by using %pe specifier for printing an error code.
Signed-off-by Sakari Ailus <[email protected]>--- drivers/platform/x86/intel/int3472/tps68470.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/platform/x86/intel/int3472/tps68470.c +1
-1@@ -161,7 +161,7 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client) regmap =devm_regmap_init_i2c (client, &tps68470_regmap_config);if (IS_ERR (regmap)) { -dev_err (&client->dev,"Failed to create regmap: %ld\n" ,PTR_ERR (regmap)); +dev_err (&client->dev,"Failed to create regmap: %pe\n" , regmap);return PTR_ERR (regmap); }
Signature · 1 line
i.
Sakari Ailus
maintainerPATCH 2/2 platform/x86: int3472: Fix uninitialised variable warning
In reply to Sakari AilusFix a smatch warning about uninitialised err_msg variable, by printing the error where it is handled.
--- drivers/platform/x86/intel/int3472/discrete.c | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/platform/x86/intel/int3472/discrete.c +10 -11
@@ -329,7 +329,6 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,unsigned long gpio_flags;union acpi_object *obj;struct gpio_desc *gpio; -const char *err_msg;const char *con_id;int ret;
@@ -375,7 +374,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,case INT3472_GPIO_TYPE_HOTPLUG_DETECT : ret =skl_int3472_map_gpio_to_sensor (int3472, agpio, con_id, gpio_flags);if (ret) - err_msg ="Failed to map GPIO pin to sensor\n" ; +dev_err (int3472->dev,"Failed to map GPIO pin to sensor\n" );break ;case INT3472_GPIO_TYPE_CLK_ENABLE :
@@ -387,7 +386,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, gpio =skl_int3472_gpiod_get_from_temp_lookup (int3472, agpio, con_id, gpio_flags);if (IS_ERR (gpio)) { ret =PTR_ERR (gpio); - err_msg ="Failed to get GPIO\n" ; +dev_err (int3472->dev,"Failed to get GPIO\n" );break ; }
@@ -395,14 +394,14 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,case INT3472_GPIO_TYPE_CLK_ENABLE : ret =skl_int3472_register_gpio_clock (int3472, gpio);if (ret) - err_msg ="Failed to register clock\n" ; +dev_err (int3472->dev,"Failed to register clock\n" );break ;case INT3472_GPIO_TYPE_PRIVACY_LED :case INT3472_GPIO_TYPE_STROBE : ret =skl_int3472_register_led (int3472, gpio, con_id);if (ret) - err_msg ="Failed to register LED\n" ; +dev_err (int3472->dev,"Failed to register LED\n" );break ;case INT3472_GPIO_TYPE_POWER_ENABLE :
@@ -413,7 +412,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, ret =skl_int3472_register_regulator (int3472, gpio, enable_time_us, con_id, second_sensor);if (ret) - err_msg ="Failed to register regulator\n" ; +dev_err (int3472->dev,"Failed to register regulator\n" );break ;default :/* Never reached */
@@ -436,11 +435,11 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, int3472->ngpios++;ACPI_FREE (obj); -if (ret <0 ) -return dev_err_probe (int3472->dev, ret, err_msg); - -/* Tell acpi_dev_get_resources() to not make a copy of the resource */ -return 1 ; +/* +* Either return an error or tell acpi_dev_get_resources() to not make a +* copy of the resource. +*/ +return ret <0 ? ret :1 ; }int int3472_discrete_parse_crs (struct int3472_discrete_device *int3472)
Signature · 1 line
2.47.3
Ilpo Järvinen
maintainerRe: [PATCH 2/2] platform/x86: int3472: Fix uninitialised variable warning
Quoted 30 lines · Sakari Ailus
Fix a smatch warning about uninitialised
err_msgvariable, by printing the error where it is handled.Signed-off-by Sakari Ailus <[email protected]>--- drivers/platform/x86/intel/int3472/discrete.c | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-)drivers/platform/x86/intel/int3472/discrete.c +1
-2@@ -329,7 +329,6 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,unsigned long gpio_flags;union acpi_object *obj;struct gpio_desc *gpio; -const char *err_msg;const char *con_id;int ret;@@ -375,7 +374,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,case INT3472_GPIO_TYPE_HOTPLUG_DETECT : ret =skl_int3472_map_gpio_to_sensor (int3472, agpio, con_id, gpio_flags);if (ret) - err_msg ="Failed to map GPIO pin to sensor\n" ; +dev_err (int3472->dev,"Failed to map GPIO pin to sensor\n" );break ;case INT3472_GPIO_TYPE_CLK_ENABLE :
drivers/platform/x86/intel/int3472/discrete.c static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, · line 392
Quoted 8 lines
drivers/platform/x86/intel/int3472/discrete.c +1
-1@@ -387,7 +386,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, gpio =skl_int3472_gpiod_get_from_temp_lookup (int3472, agpio, con_id, gpio_flags);if (IS_ERR (gpio)) { ret =PTR_ERR (gpio); - err_msg ="Failed to get GPIO\n" ; +dev_err (int3472->dev,"Failed to get GPIO\n" );break ; }
ssahiko is not happy about dev_err_probe() -> dev_err() conversion.
Quoted 27 lines
drivers/platform/x86/intel/int3472/discrete.c +3
-3@@ -395,14 +394,14 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,case INT3472_GPIO_TYPE_CLK_ENABLE : ret =skl_int3472_register_gpio_clock (int3472, gpio);if (ret) - err_msg ="Failed to register clock\n" ; +dev_err (int3472->dev,"Failed to register clock\n" );break ;case INT3472_GPIO_TYPE_PRIVACY_LED :case INT3472_GPIO_TYPE_STROBE : ret =skl_int3472_register_led (int3472, gpio, con_id);if (ret) - err_msg ="Failed to register LED\n" ; +dev_err (int3472->dev,"Failed to register LED\n" );break ;case INT3472_GPIO_TYPE_POWER_ENABLE :@@ -413,7 +412,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, ret =skl_int3472_register_regulator (int3472, gpio, enable_time_us, con_id, second_sensor);if (ret) - err_msg ="Failed to register regulator\n" ; +dev_err (int3472->dev,"Failed to register regulator\n" );break ;default :/* Never reached */
drivers/platform/x86/intel/int3472/discrete.c static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, · line 436
Quoted 2 lines
drivers/platform/x86/intel/int3472/discrete.c +0
-0@@ -436,11 +435,11 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, int3472->ngpios++;ACPI_FREE (obj);
As a general comment to logic in this function, it would be preferrable to arrange code such that the error cases inside the switch could just return directly.
To realize that, one would need to
1) use __free() for obj
2) handle that ngpios++ earlier; but I'm not even entire sure about ngpios correctness and function, it seems to be only used for indexing in acpi_evaluate_dsm_typed() (successive calls into skl_int3472_handle_gpio_resources()?) but then I don't understand why the !obj early return does not increment ngpios too.
Quoted 14 lines
drivers/platform/x86/intel/int3472/discrete.c +5
-5-if (ret <0 ) -return dev_err_probe (int3472->dev, ret, err_msg); - -/* Tell acpi_dev_get_resources() to not make a copy of the resource */ -return 1 ; +/* +* Either return an error or tell acpi_dev_get_resources() to not make a +* copy of the resource. +*/ +return ret <0 ? ret :1 ; }int int3472_discrete_parse_crs (struct int3472_discrete_device *int3472)
Signature · 1 line
i.
Sakari Ailus
maintainerRe: [PATCH 2/2] platform/x86: int3472: Fix uninitialised variable warning
Moi,
Thanks for the review.
Quoted 29 lines · Ilpo Järvinen
Quoted 27 lines · Sakari Ailus
Fix a smatch warning about uninitialised
err_msgvariable, by printing the error where it is handled.Signed-off-by Sakari Ailus <[email protected]>--- drivers/platform/x86/intel/int3472/discrete.c | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-)drivers/platform/x86/intel/int3472/discrete.c +1
-2@@ -329,7 +329,6 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,unsigned long gpio_flags;union acpi_object *obj;struct gpio_desc *gpio; -const char *err_msg;const char *con_id;int ret;@@ -375,7 +374,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,case INT3472_GPIO_TYPE_HOTPLUG_DETECT : ret =skl_int3472_map_gpio_to_sensor (int3472, agpio, con_id, gpio_flags);if (ret) - err_msg ="Failed to map GPIO pin to sensor\n" ; +dev_err (int3472->dev,"Failed to map GPIO pin to sensor\n" );
Quoted 13 lines
drivers/platform/x86/intel/int3472/discrete.c static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, · line 392
Quoted 11 lines
drivers/platform/x86/intel/int3472/discrete.c +1
-1break ;case INT3472_GPIO_TYPE_CLK_ENABLE :@@ -387,7 +386,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, gpio =skl_int3472_gpiod_get_from_temp_lookup (int3472, agpio, con_id, gpio_flags);if (IS_ERR (gpio)) { ret =PTR_ERR (gpio); - err_msg ="Failed to get GPIO\n" ; +dev_err (int3472->dev,"Failed to get GPIO\n" );break ; }ssahiko is not happy about
dev_err_probe()->dev_err()conversion.
I was wondering, too, whether I should keep it, but then again returning the error won't help here (as of now at least) and it is probably not possible -EPROBE_DEFER would be returned in these cases. I can keep using dev_err_probe() though if you prefer that.
Quoted 37 lines
Quoted 28 lines
drivers/platform/x86/intel/int3472/discrete.c +3
-3@@ -395,14 +394,14 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,case INT3472_GPIO_TYPE_CLK_ENABLE : ret =skl_int3472_register_gpio_clock (int3472, gpio);if (ret) - err_msg ="Failed to register clock\n" ; +dev_err (int3472->dev,"Failed to register clock\n" );break ;case INT3472_GPIO_TYPE_PRIVACY_LED :case INT3472_GPIO_TYPE_STROBE : ret =skl_int3472_register_led (int3472, gpio, con_id);if (ret) - err_msg ="Failed to register LED\n" ; +dev_err (int3472->dev,"Failed to register LED\n" );break ;case INT3472_GPIO_TYPE_POWER_ENABLE :@@ -413,7 +412,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, ret =skl_int3472_register_regulator (int3472, gpio, enable_time_us, con_id, second_sensor);if (ret) - err_msg ="Failed to register regulator\n" ; +dev_err (int3472->dev,"Failed to register regulator\n" );break ;default :/* Never reached */ drivers/platform/x86/intel/int3472/discrete.c static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, · line 436
Quoted 2 lines
drivers/platform/x86/intel/int3472/discrete.c +0
-0@@ -436,11 +435,11 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, int3472->ngpios++;ACPI_FREE (obj);As a general comment to logic in this function, it would be preferrable to arrange code such that the error cases inside the switch could just return directly.
To realize that, one would need to
Quoted 7 lines
1) use
__free()for obj2) handle that ngpios++ earlier; but I'm not even entire sure about ngpios correctness and function, it seems to be only used for indexing in
acpi_evaluate_dsm_typed()(successive calls intoskl_int3472_handle_gpio_resources()?) but then I don't understand why the !obj early return does not increment ngpios too.
"ngpios" is in fact an iterator. In case of an error incrementing it doesn't really matter and !obj signals the end.
I'll see how to refactor this a little in another patch. The intent here was just to fix the smatch warning as we can't currently add int3472 to Media CI because of it.
Quoted 16 lines
Quoted 15 lines
drivers/platform/x86/intel/int3472/discrete.c +5
-5-if (ret <0 ) -return dev_err_probe (int3472->dev, ret, err_msg); - -/* Tell acpi_dev_get_resources() to not make a copy of the resource */ -return 1 ; +/* +* Either return an error or tell acpi_dev_get_resources() to not make a +* copy of the resource. +*/ +return ret <0 ? ret :1 ; }int int3472_discrete_parse_crs (struct int3472_discrete_device *int3472)
Signature · 3 lines
Kind regards, Sakari Ailus
Ilpo Järvinen
maintainerRe: [PATCH 2/2] platform/x86: int3472: Fix uninitialised variable warning
Quoted 48 lines · Sakari Ailus
Moi,
Thanks for the review.
Quoted 29 lines · Ilpo Järvinen
Quoted 27 lines · Sakari Ailus
Fix a smatch warning about uninitialised
err_msgvariable, by printing the error where it is handled.Signed-off-by Sakari Ailus <[email protected]>--- drivers/platform/x86/intel/int3472/discrete.c | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-)drivers/platform/x86/intel/int3472/discrete.c +1
-2@@ -329,7 +329,6 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,unsigned long gpio_flags;union acpi_object *obj;struct gpio_desc *gpio; -const char *err_msg;const char *con_id;int ret;@@ -375,7 +374,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,case INT3472_GPIO_TYPE_HOTPLUG_DETECT : ret =skl_int3472_map_gpio_to_sensor (int3472, agpio, con_id, gpio_flags);if (ret) - err_msg ="Failed to map GPIO pin to sensor\n" ; +dev_err (int3472->dev,"Failed to map GPIO pin to sensor\n" );Quoted 13 lines
drivers/platform/x86/intel/int3472/discrete.c static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, · line 392
Quoted 11 lines
drivers/platform/x86/intel/int3472/discrete.c +1
-1break ;case INT3472_GPIO_TYPE_CLK_ENABLE :@@ -387,7 +386,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, gpio =skl_int3472_gpiod_get_from_temp_lookup (int3472, agpio, con_id, gpio_flags);if (IS_ERR (gpio)) { ret =PTR_ERR (gpio); - err_msg ="Failed to get GPIO\n" ; +dev_err (int3472->dev,"Failed to get GPIO\n" );break ; }ssahiko is not happy about
dev_err_probe()->dev_err()conversion.
Quoted 4 lines
I was wondering, too, whether I should keep it, but then again returning the error won't help here (as of now at least) and it is probably not possible -EPROBE_DEFER would be returned in these cases. I can keep using
dev_err_probe()though if you prefer that.
If sashiko is wrong and skl_int3472_gpiod_get_from_temp_lookup() cannot ever return -EPROBE_DEFER, then it doesn't matter. (But it seems reasonably good at tracking the callchains so you might want to check the detailed log if it actually found how it can return that). If it does return -EPROBE_DEFER, dev_err_probe() should be kept.
Signature · 1 line
i.
Quoted 69 lines
Quoted 36 lines
Quoted 27 lines
drivers/platform/x86/intel/int3472/discrete.c +3
-3@@ -395,14 +394,14 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,case INT3472_GPIO_TYPE_CLK_ENABLE : ret =skl_int3472_register_gpio_clock (int3472, gpio);if (ret) - err_msg ="Failed to register clock\n" ; +dev_err (int3472->dev,"Failed to register clock\n" );break ;case INT3472_GPIO_TYPE_PRIVACY_LED :case INT3472_GPIO_TYPE_STROBE : ret =skl_int3472_register_led (int3472, gpio, con_id);if (ret) - err_msg ="Failed to register LED\n" ; +dev_err (int3472->dev,"Failed to register LED\n" );break ;case INT3472_GPIO_TYPE_POWER_ENABLE :@@ -413,7 +412,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, ret =skl_int3472_register_regulator (int3472, gpio, enable_time_us, con_id, second_sensor);if (ret) - err_msg ="Failed to register regulator\n" ; +dev_err (int3472->dev,"Failed to register regulator\n" );break ;default :/* Never reached */ drivers/platform/x86/intel/int3472/discrete.c static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, · line 436
Quoted 2 lines
drivers/platform/x86/intel/int3472/discrete.c +0
-0@@ -436,11 +435,11 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, int3472->ngpios++;ACPI_FREE (obj);As a general comment to logic in this function, it would be preferrable to arrange code such that the error cases inside the switch could just return directly.
To realize that, one would need to
Quoted 7 lines
1) use
__free()for obj2) handle that ngpios++ earlier; but I'm not even entire sure about ngpios correctness and function, it seems to be only used for indexing in
acpi_evaluate_dsm_typed()(successive calls intoskl_int3472_handle_gpio_resources()?) but then I don't understand why the !obj early return does not increment ngpios too."ngpios" is in fact an iterator. In case of an error incrementing it doesn't really matter and !obj signals the end.
I'll see how to refactor this a little in another patch. The intent here was just to fix the smatch warning as we can't currently add int3472 to Media CI because of it.
Quoted 16 lines
Quoted 15 lines
drivers/platform/x86/intel/int3472/discrete.c +5
-5-if (ret <0 ) -return dev_err_probe (int3472->dev, ret, err_msg); - -/* Tell acpi_dev_get_resources() to not make a copy of the resource */ -return 1 ; +/* +* Either return an error or tell acpi_dev_get_resources() to not make a +* copy of the resource. +*/ +return ret <0 ? ret :1 ; }int int3472_discrete_parse_crs (struct int3472_discrete_device *int3472)
Sakari Ailus
maintainerRe: [PATCH 2/2] platform/x86: int3472: Fix uninitialised variable warning
Quoted 55 lines · Ilpo Järvinen
Quoted 48 lines · Sakari Ailus
Moi,
Thanks for the review.
Quoted 29 lines · Ilpo Järvinen
Quoted 27 lines · Sakari Ailus
Fix a smatch warning about uninitialised
err_msgvariable, by printing the error where it is handled.Signed-off-by Sakari Ailus <[email protected]>--- drivers/platform/x86/intel/int3472/discrete.c | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-)drivers/platform/x86/intel/int3472/discrete.c +1
-2@@ -329,7 +329,6 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,unsigned long gpio_flags;union acpi_object *obj;struct gpio_desc *gpio; -const char *err_msg;const char *con_id;int ret;@@ -375,7 +374,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,case INT3472_GPIO_TYPE_HOTPLUG_DETECT : ret =skl_int3472_map_gpio_to_sensor (int3472, agpio, con_id, gpio_flags);if (ret) - err_msg ="Failed to map GPIO pin to sensor\n" ; +dev_err (int3472->dev,"Failed to map GPIO pin to sensor\n" );Quoted 13 lines
drivers/platform/x86/intel/int3472/discrete.c static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, · line 392
Quoted 11 lines
drivers/platform/x86/intel/int3472/discrete.c +1
-1break ;case INT3472_GPIO_TYPE_CLK_ENABLE :@@ -387,7 +386,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, gpio =skl_int3472_gpiod_get_from_temp_lookup (int3472, agpio, con_id, gpio_flags);if (IS_ERR (gpio)) { ret =PTR_ERR (gpio); - err_msg ="Failed to get GPIO\n" ; +dev_err (int3472->dev,"Failed to get GPIO\n" );break ; }ssahiko is not happy about
dev_err_probe()->dev_err()conversion.Quoted 4 lines
I was wondering, too, whether I should keep it, but then again returning the error won't help here (as of now at least) and it is probably not possible -EPROBE_DEFER would be returned in these cases. I can keep using
dev_err_probe()though if you prefer that.
Quoted 5 lines
If sashiko is wrong and
skl_int3472_gpiod_get_from_temp_lookup()cannot ever return -EPROBE_DEFER, then it doesn't matter. (But it seems reasonably good at tracking the callchains so you might want to check the detailed log if it actually found how it can return that). If it does return -EPROBE_DEFER,dev_err_probe()should be kept.
I presume -EPROBE_DEFER comes from the gpiolib but it shouldn't happen here.
I think I'll still switch back to dev_err_probe() just in case, as the intention here is to avoid a build warning while cleaning up things a little.
Signature · 1 line
Sakari Ailus