Fix static analyser and compiler warnings in int3472
Sakari Ailus
maintainerv2 cover Fix static analyser and compiler warnings in int3472
Hi folks,
The two first patches address smatch and compiler warnings in int3472. The third patch adds __free() support for ACPI objects and the final two further clean up GPIO parsing in the int3472 driver.
Sakari Ailus (5):
platform/x86: int3472: Address Coccinelle warning on an error print platform/x86: int3472: Fix uninitialised variable warning
ACPI: Support __free() from cleanup.h for ACPI objects platform/x86: int3472: Release ACPI objects using __free() platform/x86: int3472: Clean up GPIO parsing
drivers/platform/x86/intel/int3472/discrete.c | 55 +++++++++---------- drivers/platform/x86/intel/int3472/tps68470.c | 2 +- include/linux/acpi.h | 2 + 3 files changed, 30 insertions(+), 29 deletions(-)
Signature · 1 line
2.47.3
Sakari Ailus
maintainerPATCH v2 1/5 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
Sakari Ailus
maintainerPATCH v2 2/5 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_probe (int3472->dev, ret,"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_probe (int3472->dev, ret,"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_probe (int3472->dev, ret,"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_probe (int3472->dev, ret,"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_probe (int3472->dev, ret,"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
Sakari Ailus
maintainerPATCH v2 3/5 ACPI: Support __free() from cleanup.h for ACPI objects
In reply to Sakari AilusUse DEFINE_FREE() to allow ACPI objects to be released automatically.
--- include/linux/acpi.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/acpi.h +2 -0
@@ -62,6 +62,8 @@ static inline acpi_handle acpi_device_handle(struct acpi_device *adev)#define ACPI_HANDLE_FWNODE (fwnode) \ acpi_device_handle(to_acpi_device_node(fwnode)) +DEFINE_FREE(ACPI_FREE, void *, ACPI_FREE(_T)) +static inline struct fwnode_handle *acpi_alloc_fwnode_static (void ) {struct fwnode_handle *fwnode;
Signature · 1 line
2.47.3
Rafael J. Wysocki (Intel)
maintainerRe: [PATCH v2 3/5] ACPI: Support __free() from cleanup.h for ACPI objects
Quoted 2 lines · Sakari Ailus
Use
DEFINE_FREE()to allow ACPI objects to be released automatically.
But at least some of them are allocated by ACPICA functions like acpi_evaluate_object() and so they have no proper constructors.
Quoted 19 lines
Signed-off-by Sakari Ailus <[email protected]>--- include/linux/acpi.h | 2 ++ 1 file changed, 2 insertions(+)include/linux/acpi.h +2
-1@@ -62,6 +62,8 @@ static inline acpi_handle acpi_device_handle(struct acpi_device *adev)#define ACPI_HANDLE_FWNODE (fwnode) \ acpi_device_handle(to_acpi_device_node(fwnode)) +DEFINE_FREE(ACPI_FREE, void *, ACPI_FREE(_T)) +static inline struct fwnode_handle *acpi_alloc_fwnode_static (void ) {struct fwnode_handle *fwnode; --
Sakari Ailus
maintainerRe: [PATCH v2 3/5] ACPI: Support __free() from cleanup.h for ACPI objects
Hi Rafael,
Quoted 7 lines · Rafael J. Wysocki (Intel)
Quoted 2 lines · Sakari Ailus
Use
DEFINE_FREE()to allow ACPI objects to be released automatically.But at least some of them are allocated by ACPICA functions like
acpi_evaluate_object()and so they have no proper constructors.
You could still assign the return buffer to a local variable. It's not ideal API-wise though.
I'm not quite sure what was the point you wanted to make but I reckon this wasn't an ack. :-)
Signature · 3 lines
Regards, Sakari Ailus
Rafael J. Wysocki (Intel)
maintainerRe: [PATCH v2 3/5] ACPI: Support __free() from cleanup.h for ACPI objects
Quoted 7 lines · Sakari Ailus
Hi Rafael,
Quoted 3 lines · Rafael J. Wysocki (Intel)
Quoted 1 line · Sakari Ailus
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Use
DEFINE_FREE()to allow ACPI objects to be released automatically.But at least some of them are allocated by ACPICA functions like
acpi_evaluate_object()and so they have no proper constructors.You could still assign the return buffer to a local variable. It's not ideal API-wise though.
Exactly.
Quoted 2 lines
I'm not quite sure what was the point you wanted to make but I reckon this wasn't an ack. :-)
Using the _FREE with variables that are not initialized through a constructor is questionable, so this is generally not particularly clean.
There is no cleanup.h in ACPICA that is a more traditional C code base, so mixing up ACPICA code, which ACPI_FREE() is strictly speaking, with cleanup.h stuff is not particularly straightforward IMV. I'd rather not do it.
Ilpo Järvinen
maintainerRe: [PATCH v2 3/5] ACPI: Support __free() from cleanup.h for ACPI objects
Quoted 17 lines · Rafael J. Wysocki (Intel)
Quoted 7 lines · Sakari Ailus
Hi Rafael,
Quoted 3 lines · Rafael J. Wysocki (Intel)
Quoted 1 line · Sakari Ailus
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Use
DEFINE_FREE()to allow ACPI objects to be released automatically.But at least some of them are allocated by ACPICA functions like
acpi_evaluate_object()and so they have no proper constructors.You could still assign the return buffer to a local variable. It's not ideal API-wise though.
Quoted 8 lines
Exactly.
Quoted 2 lines
I'm not quite sure what was the point you wanted to make but I reckon this wasn't an ack. :-)
Using the
_FREEwith variables that are not initialized through a constructor is questionable, so this is generally not particularly clean.
The driver does call ACPI_FREE() for that pointer so clearly it's already using something ending with "_FREE" already. So unless Rafael is suggesting ACPI_FREE() should be renamed, I'm a bit lost what that even means on concrete terms.
Quoted 4 lines
There is no
cleanup.hin ACPICA that is a more traditional C code base, so mixing up ACPICA code, whichACPI_FREE()is strictly speaking, withcleanup.hstuff is not particularly straightforward IMV. I'd rather not do it.
Perhaps add the DEFINE_FREE() into int3472 driver then, it seems to be what intel/pmc is already doing (I don't seem to anymore recall why it was added there). Using cleanup.h for that variable it clearly simplifies the code flow. It feels a bit stupid to duplicate it there but I guess we'll just have to live with that if there's no place in any acpi related headers for cleanup.h.
Signature · 1 line
i.
Rafael J. Wysocki (Intel)
maintainerRe: [PATCH v2 3/5] ACPI: Support __free() from cleanup.h for ACPI objects
Quoted 25 lines · Ilpo Järvinen
Quoted 22 lines · Rafael J. Wysocki (Intel)
Quoted 7 lines · Sakari Ailus
Hi Rafael,
Quoted 3 lines · Rafael J. Wysocki (Intel)
Quoted 1 line · Sakari Ailus
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Use
DEFINE_FREE()to allow ACPI objects to be released automatically.But at least some of them are allocated by ACPICA functions like
acpi_evaluate_object()and so they have no proper constructors.You could still assign the return buffer to a local variable. It's not ideal API-wise though.
Exactly.
Quoted 2 lines
I'm not quite sure what was the point you wanted to make but I reckon this wasn't an ack. :-)
Quoted 8 lines
Quoted 3 lines
Using the
_FREEwith variables that are not initialized through a constructor is questionable, so this is generally not particularly clean.The driver does call
ACPI_FREE()for that pointer so clearly it's already using something ending with "_FREE" already. So unless Rafael is suggestingACPI_FREE()should be renamed, I'm a bit lost what that even means on concrete terms.
Sorry for the confusion.
I just don't want people to do things like this:
struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER };
union acpi_object *out_obj __free(ACPI_FREE);
acpi_status status;
status = acpi_evaluate_object(handle, METHOD_NAME, NULL, &output);
if (ACPI_FAILURE(status))
return AN_ERROR;out_obj = output.pointer;
Quoted 9 lines
Quoted 4 lines
There is no
cleanup.hin ACPICA that is a more traditional C code base, so mixing up ACPICA code, whichACPI_FREE()is strictly speaking, withcleanup.hstuff is not particularly straightforward IMV. I'd rather not do it.Perhaps add the
DEFINE_FREE()into int3472 driver then, it seems to be what intel/pmc is already doing (I don't seem to anymore recall why it was added there). Usingcleanup.hfor that variable it clearly simplifies the code flow.
Well, fair enough, but as I said elsewhere, the code flow simplification can also be achieved in a different way.
Quoted 3 lines
It feels a bit stupid to duplicate it there but I guess we'll just have to live with that if there's no place in any acpi related headers for
cleanup.h.
If there is a cleanup.h "free" that can only be used with objects returned by acpi_evaluate_dsm_typed(), I'll be fine with that.
Or if everyone agrees that doing
union acpi_object *out_obj __free(ACPI_FREE) = NULL;
is not confusing and fine, I may just say "Hey, I don't care that much".
Rafael J. Wysocki (Intel)
maintainerRe: [PATCH v2 3/5] ACPI: Support __free() from cleanup.h for ACPI objects
Quoted 68 lines · Rafael J. Wysocki (Intel)
Quoted 25 lines · Ilpo Järvinen
Quoted 22 lines · Rafael J. Wysocki (Intel)
Quoted 7 lines · Sakari Ailus
Hi Rafael,
Quoted 3 lines · Rafael J. Wysocki (Intel)
Quoted 1 line · Sakari Ailus
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Use
DEFINE_FREE()to allow ACPI objects to be released automatically.But at least some of them are allocated by ACPICA functions like
acpi_evaluate_object()and so they have no proper constructors.You could still assign the return buffer to a local variable. It's not ideal API-wise though.
Exactly.
Quoted 2 lines
I'm not quite sure what was the point you wanted to make but I reckon this wasn't an ack. :-)
Quoted 8 lines
Quoted 3 lines
Using the
_FREEwith variables that are not initialized through a constructor is questionable, so this is generally not particularly clean.The driver does call
ACPI_FREE()for that pointer so clearly it's already using something ending with "_FREE" already. So unless Rafael is suggestingACPI_FREE()should be renamed, I'm a bit lost what that even means on concrete terms.Sorry for the confusion.
I just don't want people to do things like this:
struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER }; union acpi_object *out_obj __free(ACPI_FREE); acpi_status status; status = acpi_evaluate_object(handle, METHOD_NAME, NULL, &output); if (ACPI_FAILURE(status)) return AN_ERROR;out_obj = output.pointer;Quoted 9 lines
Quoted 4 lines
There is no
cleanup.hin ACPICA that is a more traditional C code base, so mixing up ACPICA code, whichACPI_FREE()is strictly speaking, withcleanup.hstuff is not particularly straightforward IMV. I'd rather not do it.Perhaps add the
DEFINE_FREE()into int3472 driver then, it seems to be what intel/pmc is already doing (I don't seem to anymore recall why it was added there). Usingcleanup.hfor that variable it clearly simplifies the code flow.Well, fair enough, but as I said elsewhere, the code flow simplification can also be achieved in a different way.
Quoted 3 lines
It feels a bit stupid to duplicate it there but I guess we'll just have to live with that if there's no place in any acpi related headers for
cleanup.h.
Quoted 8 lines
If there is a
cleanup.h"free" that can only be used with objects returned byacpi_evaluate_dsm_typed(), I'll be fine with that.Or if everyone agrees that doing
union acpi_object *out_obj __free(ACPI_FREE) = NULL;is not confusing and fine, I may just say "Hey, I don't care that much".
And particularly there is this paragraph in a comment in cleanup.h:
* Given that the "__free(...) = NULL" pattern for variables defined at
* the top of the function poses this potential interdependency problem
* the recommendation is to always define and assign variables in one
* statement and not group variable definitions at the top of the
* function when __free() is used.
regarding a broken code example, so I would think that this is not a made-up concern.
Ilpo Järvinen
maintainerRe: [PATCH v2 3/5] ACPI: Support __free() from cleanup.h for ACPI objects
Quoted 81 lines · Rafael J. Wysocki (Intel)
Quoted 68 lines · Rafael J. Wysocki (Intel)
Quoted 25 lines · Ilpo Järvinen
Quoted 22 lines · Rafael J. Wysocki (Intel)
Quoted 7 lines · Sakari Ailus
Hi Rafael,
Quoted 3 lines · Rafael J. Wysocki (Intel)
Quoted 1 line · Sakari Ailus
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Use
DEFINE_FREE()to allow ACPI objects to be released automatically.But at least some of them are allocated by ACPICA functions like
acpi_evaluate_object()and so they have no proper constructors.You could still assign the return buffer to a local variable. It's not ideal API-wise though.
Exactly.
Quoted 2 lines
I'm not quite sure what was the point you wanted to make but I reckon this wasn't an ack. :-)
Quoted 8 lines
Quoted 3 lines
Using the
_FREEwith variables that are not initialized through a constructor is questionable, so this is generally not particularly clean.The driver does call
ACPI_FREE()for that pointer so clearly it's already using something ending with "_FREE" already. So unless Rafael is suggestingACPI_FREE()should be renamed, I'm a bit lost what that even means on concrete terms.Sorry for the confusion.
I just don't want people to do things like this:
struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER }; union acpi_object *out_obj __free(ACPI_FREE); acpi_status status; status = acpi_evaluate_object(handle, METHOD_NAME, NULL, &output); if (ACPI_FAILURE(status)) return AN_ERROR;out_obj = output.pointer;Quoted 9 lines
Quoted 4 lines
There is no
cleanup.hin ACPICA that is a more traditional C code base, so mixing up ACPICA code, whichACPI_FREE()is strictly speaking, withcleanup.hstuff is not particularly straightforward IMV. I'd rather not do it.Perhaps add the
DEFINE_FREE()into int3472 driver then, it seems to be what intel/pmc is already doing (I don't seem to anymore recall why it was added there). Usingcleanup.hfor that variable it clearly simplifies the code flow.Well, fair enough, but as I said elsewhere, the code flow simplification can also be achieved in a different way.
Quoted 3 lines
It feels a bit stupid to duplicate it there but I guess we'll just have to live with that if there's no place in any acpi related headers for
cleanup.h.Quoted 8 lines
If there is a
cleanup.h"free" that can only be used with objects returned byacpi_evaluate_dsm_typed(), I'll be fine with that.Or if everyone agrees that doing
union acpi_object *out_obj __free(ACPI_FREE) = NULL;is not confusing and fine, I may just say "Hey, I don't care that much".
And particularly there is this paragraph in a comment in
cleanup.h:
Quoted 8 lines
* Given that the "
__free(...)= NULL" pattern for variables defined at
* the top of the function poses this potential interdependency problem
* the recommendation is to always define and assign variables in one
* statement and not group variable definitions at the top of the
* function when__free()is used.regarding a broken code example, so I would think that this is not a made-up concern.
That comment relates to how defining the variables at the start of functions may result in wrong/unexpected cleanup order. More imporantly, the comment is not an argument for not using __free() but an instruction on what is the correct pattern to use it so those ordering issues do not occur.
The cleanups will execute in reverse order the variables where defined so a variable defined at start may be cleaned up only after releasing a lock that was taken mid-function (which often is safe but one can easily envision cases where the lock should be still held when the cleanup runs).
Signature · 1 line
i.
Rafael J. Wysocki (Intel)
maintainerRe: [PATCH v2 3/5] ACPI: Support __free() from cleanup.h for ACPI objects
Quoted 99 lines · Ilpo Järvinen
Quoted 81 lines · Rafael J. Wysocki (Intel)
Quoted 68 lines · Rafael J. Wysocki (Intel)
Quoted 25 lines · Ilpo Järvinen
Quoted 22 lines · Rafael J. Wysocki (Intel)
Quoted 7 lines · Sakari Ailus
Hi Rafael,
Quoted 3 lines · Rafael J. Wysocki (Intel)
Quoted 1 line · Sakari Ailus
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Use
DEFINE_FREE()to allow ACPI objects to be released automatically.But at least some of them are allocated by ACPICA functions like
acpi_evaluate_object()and so they have no proper constructors.You could still assign the return buffer to a local variable. It's not ideal API-wise though.
Exactly.
Quoted 2 lines
I'm not quite sure what was the point you wanted to make but I reckon this wasn't an ack. :-)
Quoted 8 lines
Quoted 3 lines
Using the
_FREEwith variables that are not initialized through a constructor is questionable, so this is generally not particularly clean.The driver does call
ACPI_FREE()for that pointer so clearly it's already using something ending with "_FREE" already. So unless Rafael is suggestingACPI_FREE()should be renamed, I'm a bit lost what that even means on concrete terms.Sorry for the confusion.
I just don't want people to do things like this:
struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER }; union acpi_object *out_obj __free(ACPI_FREE); acpi_status status; status = acpi_evaluate_object(handle, METHOD_NAME, NULL, &output); if (ACPI_FAILURE(status)) return AN_ERROR;out_obj = output.pointer;Quoted 9 lines
Quoted 4 lines
There is no
cleanup.hin ACPICA that is a more traditional C code base, so mixing up ACPICA code, whichACPI_FREE()is strictly speaking, withcleanup.hstuff is not particularly straightforward IMV. I'd rather not do it.Perhaps add the
DEFINE_FREE()into int3472 driver then, it seems to be what intel/pmc is already doing (I don't seem to anymore recall why it was added there). Usingcleanup.hfor that variable it clearly simplifies the code flow.Well, fair enough, but as I said elsewhere, the code flow simplification can also be achieved in a different way.
Quoted 3 lines
It feels a bit stupid to duplicate it there but I guess we'll just have to live with that if there's no place in any acpi related headers for
cleanup.h.Quoted 8 lines
If there is a
cleanup.h"free" that can only be used with objects returned byacpi_evaluate_dsm_typed(), I'll be fine with that.Or if everyone agrees that doing
union acpi_object *out_obj __free(ACPI_FREE) = NULL;is not confusing and fine, I may just say "Hey, I don't care that much".
And particularly there is this paragraph in a comment in
cleanup.h:Quoted 8 lines
* Given that the "
__free(...)= NULL" pattern for variables defined at
* the top of the function poses this potential interdependency problem
* the recommendation is to always define and assign variables in one
* statement and not group variable definitions at the top of the
* function when__free()is used.regarding a broken code example, so I would think that this is not a made-up concern.
That comment relates to how defining the variables at the start of functions may result in wrong/unexpected cleanup order. More imporantly, the comment is not an argument for not using
__free()but an instruction on what is the correct pattern to use it so those ordering issues do not occur.
Quoted 4 lines
The cleanups will execute in reverse order the variables where defined so a variable defined at start may be cleaned up only after releasing a lock that was taken mid-function (which often is safe but one can easily envision cases where the lock should be still held when the cleanup runs).
I agree with all of the above.
Though I think that cleanup ordering issues are easier to overlook when the "__free(...) = NULL" pattern is used, which is why I wouldn't like to encourage using it.
Sakari Ailus
maintainerRe: [PATCH v2 3/5] ACPI: Support __free() from cleanup.h for ACPI objects
In reply to Rafael J. Wysocki (Intel)Hi Rafael, Ilpo,
Quoted 11 lines · Rafael J. Wysocki (Intel)
Quoted 8 lines
If there is a
cleanup.h"free" that can only be used with objects returned byacpi_evaluate_dsm_typed(), I'll be fine with that.Or if everyone agrees that doing
union acpi_object *out_obj __free(ACPI_FREE) = NULL;is not confusing and fine, I may just say "Hey, I don't care that much".
And particularly there is this paragraph in a comment in
cleanup.h:
Quoted 8 lines
* Given that the "
__free(...)= NULL" pattern for variables defined at
* the top of the function poses this potential interdependency problem
* the recommendation is to always define and assign variables in one
* statement and not group variable definitions at the top of the
* function when__free()is used.regarding a broken code example, so I would think that this is not a made-up concern.
That's indeed a valid concern, still quite unlikely in practice but probably hard to find when it happens, so avoiding that is definitely preferred. That being said, the biggest trap in cleanup.h is probably in scoped_guard(), and doing __free() = NULL somewhere doesn't matter much in the end.
In this case I'll just call ACPI_FREE() sooner.
Signature · 3 lines
Regards, Sakari Ailus
Ilpo Järvinen
maintainerRe: [PATCH v2 3/5] ACPI: Support __free() from cleanup.h for ACPI objects
Quoted 20 lines · Sakari Ailus
Hi Rafael, Ilpo,
Quoted 17 lines · Rafael J. Wysocki (Intel)
Quoted 8 lines
If there is a
cleanup.h"free" that can only be used with objects returned byacpi_evaluate_dsm_typed(), I'll be fine with that.Or if everyone agrees that doing
union acpi_object *out_obj __free(ACPI_FREE) = NULL;is not confusing and fine, I may just say "Hey, I don't care that much".
And particularly there is this paragraph in a comment in
cleanup.h:* Given that the "
__free(...)= NULL" pattern for variables defined at
* the top of the function poses this potential interdependency problem
* the recommendation is to always define and assign variables in one
* statement and not group variable definitions at the top of the
* function when__free()is used.
Quoted 8 lines
Quoted 2 lines
regarding a broken code example, so I would think that this is not a made-up concern.
That's indeed a valid concern, still quite unlikely in practice but probably hard to find when it happens, so avoiding that is definitely preferred. That being said, the biggest trap in
cleanup.his probably inscoped_guard(), and doing__free()= NULL somewhere doesn't matter much in the end.
__free() = NULL is not that hard to catch during review (or even in code already in-tree), have done that dozens of times myself by now. Checkpatch, too, should be able to catch that easily, if it doesn't already.
None of those cases I've commented on had a bug, so it was just for teaching submitters & readers of that code the correct __free() pattern. I think the concern is largely overblown given how rare actual bugs are even if the wrong pattern is used. Put that to contrast to memleaks found on our rollback paths, __free() looks a clear win despite very rare to occur caveats.
Given what I've seen, I'd say on dangerous level __free() = NULL is somewhere around using MAGIC_SIZE_DEFINE instead sizeof(*obj) when doing mem allocs. It usually isn't buggy even if we don't want to teach people to use it.
Besides, it was actually Rafael himself who brought the unsafe pattern into this discussion (I immediately noticed the problem but since it was not an actual patch, I didn't raise a concern). Sakari's patch did use the correct pattern (and if it wouldn't have done so, there would have been a review comment from me ;-)). In my reply to Rafael, I intentionally left the right side open with "= ..." to not place that NULL there.
Quoted 1 line
In this case I'll just call
ACPI_FREE()sooner.
That works too in this case, yes.
Signature · 1 line
i.
Rafael J. Wysocki (Intel)
maintainerRe: [PATCH v2 3/5] ACPI: Support __free() from cleanup.h for ACPI objects
Quoted 56 lines · Ilpo Järvinen
Quoted 20 lines · Sakari Ailus
Hi Rafael, Ilpo,
Quoted 17 lines · Rafael J. Wysocki (Intel)
Quoted 8 lines
If there is a
cleanup.h"free" that can only be used with objects returned byacpi_evaluate_dsm_typed(), I'll be fine with that.Or if everyone agrees that doing
union acpi_object *out_obj __free(ACPI_FREE) = NULL;is not confusing and fine, I may just say "Hey, I don't care that much".
And particularly there is this paragraph in a comment in
cleanup.h:* Given that the "
__free(...)= NULL" pattern for variables defined at
* the top of the function poses this potential interdependency problem
* the recommendation is to always define and assign variables in one
* statement and not group variable definitions at the top of the
* function when__free()is used.Quoted 8 lines
Quoted 2 lines
regarding a broken code example, so I would think that this is not a made-up concern.
That's indeed a valid concern, still quite unlikely in practice but probably hard to find when it happens, so avoiding that is definitely preferred. That being said, the biggest trap in
cleanup.his probably inscoped_guard(), and doing__free()= NULL somewhere doesn't matter much in the end.
__free()= NULL is not that hard to catch during review (or even in code already in-tree), have done that dozens of times myself by now. Checkpatch, too, should be able to catch that easily, if it doesn't already.None of those cases I've commented on had a bug, so it was just for teaching submitters & readers of that code the correct
__free()pattern. I think the concern is largely overblown given how rare actual bugs are even if the wrong pattern is used. Put that to contrast to memleaks found on our rollback paths,__free()looks a clear win despite very rare to occur caveats.Given what I've seen, I'd say on dangerous level
__free()= NULL is somewhere around usingMAGIC_SIZE_DEFINEinsteadsizeof(*obj)when doing mem allocs. It usually isn't buggy even if we don't want to teach people to use it.Besides, it was actually Rafael himself who brought the unsafe pattern into this discussion (I immediately noticed the problem but since it was not an actual patch, I didn't raise a concern). Sakari's patch did use the correct pattern (and if it wouldn't have done so, there would have been a review comment from me ;-)). In my reply to Rafael, I intentionally left the right side open with "= ..." to not place that NULL there.
Quoted 3 lines
Quoted 1 line
In this case I'll just call
ACPI_FREE()sooner.That works too in this case, yes.
So overall, something like this can be defined
static inline void free_acpi_object(union acpi_object *obj)
{
ACPI_FREE(obj);
}DEFINE_FREE(acpi_object_free, union acpi_object *, free_acpi_object(_T))
and used along with acpi_evaluate_dsm*().
Moreover, a wrapper around acpi_evaluate_object() returning a pointer to union acpi_object on success and NULL on failure can be defined and used along with the above.
IMV that would be way cleaner than wrapping a raw cleanup macro around ACPI_FREE().
I generally think that there needs to be a wrapper layer around the ACPICA API, so drivers don't need to call functions returning acpi_status directly, for instance.
Someday we'll get there.
Ilpo Järvinen
maintainerRe: [PATCH v2 3/5] ACPI: Support __free() from cleanup.h for ACPI objects
In reply to Rafael J. Wysocki (Intel)Quoted 63 lines · Rafael J. Wysocki (Intel)
Quoted 25 lines · Ilpo Järvinen
Quoted 22 lines · Rafael J. Wysocki (Intel)
Quoted 7 lines · Sakari Ailus
Hi Rafael,
Quoted 3 lines · Rafael J. Wysocki (Intel)
Quoted 1 line · Sakari Ailus
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Use
DEFINE_FREE()to allow ACPI objects to be released automatically.But at least some of them are allocated by ACPICA functions like
acpi_evaluate_object()and so they have no proper constructors.You could still assign the return buffer to a local variable. It's not ideal API-wise though.
Exactly.
Quoted 2 lines
I'm not quite sure what was the point you wanted to make but I reckon this wasn't an ack. :-)
Quoted 8 lines
Quoted 3 lines
Using the
_FREEwith variables that are not initialized through a constructor is questionable, so this is generally not particularly clean.The driver does call
ACPI_FREE()for that pointer so clearly it's already using something ending with "_FREE" already. So unless Rafael is suggestingACPI_FREE()should be renamed, I'm a bit lost what that even means on concrete terms.Sorry for the confusion.
I just don't want people to do things like this:
struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER }; union acpi_object *out_obj __free(ACPI_FREE); acpi_status status; status = acpi_evaluate_object(handle, METHOD_NAME, NULL, &output); if (ACPI_FAILURE(status)) return AN_ERROR;out_obj = output.pointer;Quoted 9 lines
Quoted 4 lines
There is no
cleanup.hin ACPICA that is a more traditional C code base, so mixing up ACPICA code, whichACPI_FREE()is strictly speaking, withcleanup.hstuff is not particularly straightforward IMV. I'd rather not do it.Perhaps add the
DEFINE_FREE()into int3472 driver then, it seems to be what intel/pmc is already doing (I don't seem to anymore recall why it was added there). Usingcleanup.hfor that variable it clearly simplifies the code flow.Well, fair enough, but as I said elsewhere, the code flow simplification can also be achieved in a different way.
Quoted 6 lines
Quoted 3 lines
It feels a bit stupid to duplicate it there but I guess we'll just have to live with that if there's no place in any acpi related headers for
cleanup.h.If there is a
cleanup.h"free" that can only be used with objects returned byacpi_evaluate_dsm_typed(), I'll be fine with that.
So you'd be fine with something like this:
union acpi_object *out_obj __free(some_other_name_than_ACPI_FREE) = ...
?
Quoted 5 lines
Or if everyone agrees that doing
union acpi_object *out_obj __free(ACPI_FREE) = NULL;is not confusing and fine, I may just say "Hey, I don't care that much".
I personally don't hang myself into "free" or "constructor" terminology but look it more pragmatically, if ACPI_FREE() should be called before the object goes out of scope, __free() is a tool for that.
Have Rust people tried to wrap this interface already (there seems to acpi.rs but it seems very limited in scope)? I'd expect them to be just as interested in knowing what to do when something is at the end of its lifetime.
Signature · 1 line
i.
Rafael J. Wysocki (Intel)
maintainerRe: [PATCH v2 3/5] ACPI: Support __free() from cleanup.h for ACPI objects
Quoted 70 lines · Ilpo Järvinen
Quoted 67 lines · Rafael J. Wysocki (Intel)
Quoted 25 lines · Ilpo Järvinen
Quoted 22 lines · Rafael J. Wysocki (Intel)
Quoted 7 lines · Sakari Ailus
Hi Rafael,
Quoted 3 lines · Rafael J. Wysocki (Intel)
Quoted 1 line · Sakari Ailus
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Use
DEFINE_FREE()to allow ACPI objects to be released automatically.But at least some of them are allocated by ACPICA functions like
acpi_evaluate_object()and so they have no proper constructors.You could still assign the return buffer to a local variable. It's not ideal API-wise though.
Exactly.
Quoted 2 lines
I'm not quite sure what was the point you wanted to make but I reckon this wasn't an ack. :-)
Quoted 8 lines
Quoted 3 lines
Using the
_FREEwith variables that are not initialized through a constructor is questionable, so this is generally not particularly clean.The driver does call
ACPI_FREE()for that pointer so clearly it's already using something ending with "_FREE" already. So unless Rafael is suggestingACPI_FREE()should be renamed, I'm a bit lost what that even means on concrete terms.Sorry for the confusion.
I just don't want people to do things like this:
struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER }; union acpi_object *out_obj __free(ACPI_FREE); acpi_status status; status = acpi_evaluate_object(handle, METHOD_NAME, NULL, &output); if (ACPI_FAILURE(status)) return AN_ERROR;out_obj = output.pointer;Quoted 9 lines
Quoted 4 lines
There is no
cleanup.hin ACPICA that is a more traditional C code base, so mixing up ACPICA code, whichACPI_FREE()is strictly speaking, withcleanup.hstuff is not particularly straightforward IMV. I'd rather not do it.Perhaps add the
DEFINE_FREE()into int3472 driver then, it seems to be what intel/pmc is already doing (I don't seem to anymore recall why it was added there). Usingcleanup.hfor that variable it clearly simplifies the code flow.Well, fair enough, but as I said elsewhere, the code flow simplification can also be achieved in a different way.
Quoted 3 lines
It feels a bit stupid to duplicate it there but I guess we'll just have to live with that if there's no place in any acpi related headers for
cleanup.h.
Quoted 8 lines
Quoted 2 lines
If there is a
cleanup.h"free" that can only be used with objects returned byacpi_evaluate_dsm_typed(), I'll be fine with that.So you'd be fine with something like this:
union
acpi_object*out_obj__free(some_other_name_than_ACPI_FREE)= ...?
Basically, yes.
Quoted 9 lines
Quoted 5 lines
Or if everyone agrees that doing
union acpi_object *out_obj __free(ACPI_FREE) = NULL;is not confusing and fine, I may just say "Hey, I don't care that much".
I personally don't hang myself into "free" or "constructor" terminology but look it more pragmatically, if
ACPI_FREE()should be called before the object goes out of scope,__free()is a tool for that.
It is also good to consider the example given in cleanup.h though, in which there is the
struct object *obj __free(remove_free) = NULL;
pattern leading to a real bug due to a cleanup ordering issue.
I would prefer to avoid encouraging people to create code patterns that are potentially problematic. The "free" or "constructor" terminology mentioned above boils down to avoiding those code patterns which also matters in practice.
Quoted 4 lines
Have Rust people tried to wrap this interface already (there seems to
acpi.rsbut it seems very limited in scope)? I'd expect them to be just as interested in knowing what to do when something is at the end of its lifetime.
No, they haven't, AFAICS. At least I'm not aware of any attempts to do so.
Sakari Ailus
maintainerPATCH v2 4/5 platform/x86: int3472: Release ACPI objects using __free()
In reply to Sakari AilusUse __free() to release ACPI objects received from acpi_evaluate_dsm_typed() without explicit ACPI_FREE().
--- drivers/platform/x86/intel/int3472/discrete.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/platform/x86/intel/int3472/discrete.c +6 -6
@@ -4,6 +4,7 @@#include <linux/acpi.h> #include <linux/array_size.h> #include <linux/bitfield.h> +#include <linux/cleanup.h> #include <linux/device.h> #include <linux/dmi.h> #include <linux/gpio/consumer.h>
@@ -327,7 +328,6 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,unsigned int enable_time_us;u8 active_value, pin, type;unsigned long gpio_flags; -union acpi_object *obj;struct gpio_desc *gpio;const char *con_id;int ret;
@@ -339,10 +339,11 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,* ngpios + 2 because the index of this _DSM function is 1-based and * the first function is just a count. */ - obj =acpi_evaluate_dsm_typed (int3472->adev->handle, - &int3472_gpio_guid,0x00 , - int3472->ngpios +2 , -NULL ,ACPI_TYPE_INTEGER ); + union acpi_object *obj __free(ACPI_FREE) = +acpi_evaluate_dsm_typed (int3472->adev->handle, + &int3472_gpio_guid,0x00 , + int3472->ngpios +2 , +NULL ,ACPI_TYPE_INTEGER );if (!obj) { dev_warn(int3472->dev, "No _DSM entry for GPIO pin %u\n",
@@ -433,7 +434,6 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, } int3472->ngpios++; -ACPI_FREE (obj);/* * Either return an error or tell acpi_dev_get_resources() to not make a
Signature · 1 line
2.47.3
Rafael J. Wysocki (Intel)
maintainerRe: [PATCH v2 4/5] platform/x86: int3472: Release ACPI objects using __free()
Quoted 3 lines · Sakari Ailus
Use
__free()to release ACPI objects received fromacpi_evaluate_dsm_typed()without explicitACPI_FREE().
Well, the benefit of doing so is not entirely clear to me.
At least there is more overhead in the new code, or am I mistaken?
Quoted 52 lines
Signed-off-by Sakari Ailus <[email protected]>--- drivers/platform/x86/intel/int3472/discrete.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/platform/x86/intel/int3472/discrete.c +6
-7@@ -4,6 +4,7 @@#include <linux/acpi.h> #include <linux/array_size.h> #include <linux/bitfield.h> +#include <linux/cleanup.h> #include <linux/device.h> #include <linux/dmi.h> #include <linux/gpio/consumer.h> @@ -327,7 +328,6 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,unsigned int enable_time_us;u8 active_value, pin, type;unsigned long gpio_flags; -union acpi_object *obj;struct gpio_desc *gpio;const char *con_id;int ret;@@ -339,10 +339,11 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,* ngpios + 2 because the index of this _DSM function is 1-based and * the first function is just a count. */ - obj =acpi_evaluate_dsm_typed (int3472->adev->handle, - &int3472_gpio_guid,0x00 , - int3472->ngpios +2 , -NULL ,ACPI_TYPE_INTEGER ); + union acpi_object *obj __free(ACPI_FREE) = +acpi_evaluate_dsm_typed (int3472->adev->handle, + &int3472_gpio_guid,0x00 , + int3472->ngpios +2 , +NULL ,ACPI_TYPE_INTEGER );if (!obj) { dev_warn(int3472->dev, "No _DSM entry for GPIO pin %u\n",@@ -433,7 +434,6 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, } int3472->ngpios++; -ACPI_FREE (obj);/* * Either return an error or tell acpi_dev_get_resources() to not make a -- 2.47.3
Sakari Ailus
maintainerRe: [PATCH v2 4/5] platform/x86: int3472: Release ACPI objects using __free()
Hi Rafael,
Thank you for the review.
Quoted 9 lines · Rafael J. Wysocki (Intel)
Quoted 3 lines · Sakari Ailus
Use
__free()to release ACPI objects received fromacpi_evaluate_dsm_typed()without explicitACPI_FREE().Well, the benefit of doing so is not entirely clear to me.
At least there is more overhead in the new code, or am I mistaken?
It becomes possible to simplify error handling mid-function. See the 5th patch -- perhaps squashing this with that would make this more visible?
Signature · 3 lines
Regards, Sakari Ailus
Rafael J. Wysocki (Intel)
maintainerRe: [PATCH v2 4/5] platform/x86: int3472: Release ACPI objects using __free()
Quoted 12 lines · Sakari Ailus
Hi Rafael,
Thank you for the review.
Quoted 6 lines · Rafael J. Wysocki (Intel)
Quoted 3 lines · Sakari Ailus
Use
__free()to release ACPI objects received fromacpi_evaluate_dsm_typed()without explicitACPI_FREE().
Quoted 6 lines
Quoted 3 lines
Well, the benefit of doing so is not entirely clear to me.
At least there is more overhead in the new code, or am I mistaken?
It becomes possible to simplify error handling mid-function. See the 5th patch -- perhaps squashing this with that would make this more visible?
Possibly, but this may also be achieved by processing the object coming from the ACPICA code in a separate function. For example
obj = acpi_evaluate_dsm_typed(args);
ret = do_stuff_with_obj(obj);ACPI_FREE(obj);
return ret;
and the error handling in do_stuff_with_obj() can be just like in the case when __free() is used in the caller.
Of course, you may argue that acpi_evaluate_dsm_typed() can be used as a proper constructor, so this is all fine, but IMV it is a special case and I'm not quite comfortable with defining a _FREE that looks general enough for this particular special case.
Sakari Ailus
maintainerPATCH v2 5/5 platform/x86: int3472: Clean up GPIO parsing
In reply to Sakari AilusIn skl_int3472_handle_gpio_resources(), return an error where it happens, except when we're holding a reference to a GPIO. This involves incrementing ngpios earlier on but that does not introduce a functional change.
--- drivers/platform/x86/intel/int3472/discrete.c | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-)
drivers/platform/x86/intel/int3472/discrete.c +21 -21
@@ -369,15 +369,23 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, agpio->resource_source.string_ptr, agpio->pin_table[0 ], str_high_low(gpio_flags == GPIO_ACTIVE_HIGH)); +/* +* int3472->ngpios can be incremented here as it is an argument to the +* _DSM, not e.g. an index to an array in C. Additionally, in case of an +* error the value won't be used. +*/ + int3472->ngpios++; +switch (type) {case INT3472_GPIO_TYPE_RESET :case INT3472_GPIO_TYPE_POWERDOWN :case INT3472_GPIO_TYPE_HOTPLUG_DETECT : ret =skl_int3472_map_gpio_to_sensor (int3472, agpio, con_id, gpio_flags);if (ret) -dev_err_probe (int3472->dev, ret,"Failed to map GPIO pin to sensor\n" ); +return dev_err_probe (int3472->dev, ret, +"Failed to map GPIO pin to sensor\n" ); -break ; +return 0 ;case INT3472_GPIO_TYPE_CLK_ENABLE :case INT3472_GPIO_TYPE_PRIVACY_LED :case INT3472_GPIO_TYPE_STROBE :
@@ -385,24 +393,24 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,case INT3472_GPIO_TYPE_DOVDD :case INT3472_GPIO_TYPE_HANDSHAKE : gpio =skl_int3472_gpiod_get_from_temp_lookup (int3472, agpio, con_id, gpio_flags); -if (IS_ERR (gpio)) { - ret =PTR_ERR (gpio); -dev_err_probe (int3472->dev, ret,"Failed to get GPIO\n" ); -break ; - } +if (IS_ERR (gpio)) +return dev_err_probe (int3472->dev,PTR_ERR (gpio), +"Failed to get GPIO\n" );switch (type) {case INT3472_GPIO_TYPE_CLK_ENABLE : ret =skl_int3472_register_gpio_clock (int3472, gpio);if (ret) -dev_err_probe (int3472->dev, ret,"Failed to register clock\n" ); +dev_err_probe (int3472->dev, ret, +"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) -dev_err_probe (int3472->dev, ret,"Failed to register LED\n" ); +dev_err_probe (int3472->dev, ret, +"Failed to register LED\n" );break ;case INT3472_GPIO_TYPE_POWER_ENABLE :
@@ -413,7 +421,8 @@ 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) -dev_err_probe (int3472->dev, ret,"Failed to register regulator\n" ); +dev_err_probe (int3472->dev, ret, +"Failed to register regulator\n" );break ;default :/* Never reached */
@@ -424,22 +433,13 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,if (ret)gpiod_put (gpio); -break ; +return ret;default :dev_warn (int3472->dev,"GPIO type 0x%02x unknown; the sensor may not work\n" , type); - ret =1 ; -break ; +return 1 ; } - - int3472->ngpios++; - -/* -* 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 v2 5/5] platform/x86: int3472: Clean up GPIO parsing
Quoted 15 lines · Sakari Ailus
In
skl_int3472_handle_gpio_resources(), return an error where it happens, except when we're holding a reference to a GPIO. This involves incrementing ngpios earlier on but that does not introduce a functional change.Signed-off-by Sakari Ailus <[email protected]>--- drivers/platform/x86/intel/int3472/discrete.c | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-)drivers/platform/x86/intel/int3472/discrete.c +0
-0
drivers/platform/x86/intel/int3472/discrete.c static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, · line 376
Quoted 8 lines
drivers/platform/x86/intel/int3472/discrete.c +5
-0@@ -369,15 +369,23 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, agpio->resource_source.string_ptr, agpio->pin_table[0 ], str_high_low(gpio_flags == GPIO_ACTIVE_HIGH)); +/* +* int3472->ngpios can be incremented here as it is an argument to the +* _DSM, not e.g. an index to an array in C. Additionally, in case of an +* error the value won't be used. +*/
I wasn't expecting comment for this. You might have added it because of my questions but IMO it's not needed.
I think just the old way/place was confusing, especially given how some/part of the error cases did increment it. But after moving it here, it makes much more sense even without that comment.
And one can determine it's not being used for C arrays by using grep so that too seems just unnecessary detail.
Quoted 27 lines
drivers/platform/x86/intel/int3472/discrete.c +6
-7+ int3472->ngpios++; +switch (type) {case INT3472_GPIO_TYPE_RESET :case INT3472_GPIO_TYPE_POWERDOWN :case INT3472_GPIO_TYPE_HOTPLUG_DETECT : ret =skl_int3472_map_gpio_to_sensor (int3472, agpio, con_id, gpio_flags);if (ret) -dev_err_probe (int3472->dev, ret,"Failed to map GPIO pin to sensor\n" ); +return dev_err_probe (int3472->dev, ret, +"Failed to map GPIO pin to sensor\n" ); -break ; +return 0 ;case INT3472_GPIO_TYPE_CLK_ENABLE :case INT3472_GPIO_TYPE_PRIVACY_LED :case INT3472_GPIO_TYPE_STROBE :@@ -385,24 +393,24 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,case INT3472_GPIO_TYPE_DOVDD :case INT3472_GPIO_TYPE_HANDSHAKE : gpio =skl_int3472_gpiod_get_from_temp_lookup (int3472, agpio, con_id, gpio_flags); -if (IS_ERR (gpio)) { - ret =PTR_ERR (gpio); -dev_err_probe (int3472->dev, ret,"Failed to get GPIO\n" ); -break ; - } +if (IS_ERR (gpio))
drivers/platform/x86/intel/int3472/discrete.c static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, · line 405
Quoted 10 lines
drivers/platform/x86/intel/int3472/discrete.c +4
-1+return dev_err_probe (int3472->dev,PTR_ERR (gpio), +"Failed to get GPIO\n" );switch (type) {case INT3472_GPIO_TYPE_CLK_ENABLE : ret =skl_int3472_register_gpio_clock (int3472, gpio);if (ret) -dev_err_probe (int3472->dev, ret,"Failed to register clock\n" ); +dev_err_probe (int3472->dev, ret, +"Failed to register clock\n" );
Don't know why changed linesplits in this instead doing them directly in the 2nd patch.
Quoted 48 lines
drivers/platform/x86/intel/int3472/discrete.c +6
-13break ;case INT3472_GPIO_TYPE_PRIVACY_LED :case INT3472_GPIO_TYPE_STROBE : ret =skl_int3472_register_led (int3472, gpio, con_id);if (ret) -dev_err_probe (int3472->dev, ret,"Failed to register LED\n" ); +dev_err_probe (int3472->dev, ret, +"Failed to register LED\n" );break ;case INT3472_GPIO_TYPE_POWER_ENABLE :@@ -413,7 +421,8 @@ 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) -dev_err_probe (int3472->dev, ret,"Failed to register regulator\n" ); +dev_err_probe (int3472->dev, ret, +"Failed to register regulator\n" );break ;default :/* Never reached */ @@ -424,22 +433,13 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,if (ret)gpiod_put (gpio); -break ; +return ret;default :dev_warn (int3472->dev,"GPIO type 0x%02x unknown; the sensor may not work\n" , type); - ret =1 ; -break ; +return 1 ; } - - int3472->ngpios++; - -/* -* 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 v2 5/5] platform/x86: int3472: Clean up GPIO parsing
Moi,
Quoted 29 lines · Ilpo Järvinen
Quoted 15 lines · Sakari Ailus
In
skl_int3472_handle_gpio_resources(), return an error where it happens, except when we're holding a reference to a GPIO. This involves incrementing ngpios earlier on but that does not introduce a functional change.Signed-off-by Sakari Ailus <[email protected]>--- drivers/platform/x86/intel/int3472/discrete.c | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-)drivers/platform/x86/intel/int3472/discrete.c +0
-0drivers/platform/x86/intel/int3472/discrete.c static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, · line 376
Quoted 8 lines
drivers/platform/x86/intel/int3472/discrete.c +5
-0@@ -369,15 +369,23 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, agpio->resource_source.string_ptr, agpio->pin_table[0 ], str_high_low(gpio_flags == GPIO_ACTIVE_HIGH)); +/* +* int3472->ngpios can be incremented here as it is an argument to the +* _DSM, not e.g. an index to an array in C. Additionally, in case of an +* error the value won't be used. +*/ I wasn't expecting comment for this. You might have added it because of my questions but IMO it's not needed.
Quoted 6 lines
I think just the old way/place was confusing, especially given how some/part of the error cases did increment it. But after moving it here, it makes much more sense even without that comment.
And one can determine it's not being used for C arrays by using grep so that too seems just unnecessary detail.
Ok, I'll drop it.
Quoted 31 lines
Quoted 31 lines
drivers/platform/x86/intel/int3472/discrete.c +8
-7+ int3472->ngpios++; +switch (type) {case INT3472_GPIO_TYPE_RESET :case INT3472_GPIO_TYPE_POWERDOWN :case INT3472_GPIO_TYPE_HOTPLUG_DETECT : ret =skl_int3472_map_gpio_to_sensor (int3472, agpio, con_id, gpio_flags);if (ret) -dev_err_probe (int3472->dev, ret,"Failed to map GPIO pin to sensor\n" ); +return dev_err_probe (int3472->dev, ret, +"Failed to map GPIO pin to sensor\n" ); -break ; +return 0 ;case INT3472_GPIO_TYPE_CLK_ENABLE :case INT3472_GPIO_TYPE_PRIVACY_LED :case INT3472_GPIO_TYPE_STROBE :@@ -385,24 +393,24 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,case INT3472_GPIO_TYPE_DOVDD :case INT3472_GPIO_TYPE_HANDSHAKE : gpio =skl_int3472_gpiod_get_from_temp_lookup (int3472, agpio, con_id, gpio_flags); -if (IS_ERR (gpio)) { - ret =PTR_ERR (gpio); -dev_err_probe (int3472->dev, ret,"Failed to get GPIO\n" ); -break ; - } +if (IS_ERR (gpio)) +return dev_err_probe (int3472->dev,PTR_ERR (gpio), +"Failed to get GPIO\n" );
Quoted 10 lines
drivers/platform/x86/intel/int3472/discrete.c static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares, · line 405
Quoted 7 lines
drivers/platform/x86/intel/int3472/discrete.c +2
-1switch (type) {case INT3472_GPIO_TYPE_CLK_ENABLE : ret =skl_int3472_register_gpio_clock (int3472, gpio);if (ret) -dev_err_probe (int3472->dev, ret,"Failed to register clock\n" ); +dev_err_probe (int3472->dev, ret, +"Failed to register clock\n" );Don't know why changed linesplits in this instead doing them directly in the 2nd patch.
Oops, that's where I intended to make them. I'll fix that for v3.
Signature · 1 line
Sakari Ailus