diff mbox series

[1/2] power: supply: core: simplify with cleanup.h

Message ID 20240705113113.42851-1-krzysztof.kozlowski@linaro.org (mailing list archive)
State Handled Elsewhere, archived
Headers show
Series [1/2] power: supply: core: simplify with cleanup.h | expand

Commit Message

Krzysztof Kozlowski July 5, 2024, 11:31 a.m. UTC
Allocate the memory with scoped/cleanup.h to reduce error handling and
make the code a bit simpler.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/power/supply/power_supply_core.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Krzysztof Kozlowski Aug. 21, 2024, 1:56 p.m. UTC | #1
On 05/07/2024 13:31, Krzysztof Kozlowski wrote:
> Allocate the memory with scoped/cleanup.h to reduce error handling and
> make the code a bit simpler.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
>  drivers/power/supply/power_supply_core.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 

Sebastian,

Any comments on these patches?

Best regards,
Krzysztof
Sebastian Reichel Aug. 27, 2024, 4:25 p.m. UTC | #2
On Fri, 05 Jul 2024 13:31:12 +0200, Krzysztof Kozlowski wrote:
> Allocate the memory with scoped/cleanup.h to reduce error handling and
> make the code a bit simpler.
> 
> 

Applied, thanks!

[1/2] power: supply: core: simplify with cleanup.h
      commit: a9125e868f7ad80d527cf5c69e20fa0ada96bff9
[2/2] power: supply: twl4030_charger: correct comparision with old current
      commit: e764374f4b57a0e0c0221bc0188034ae9996808e

Best regards,
diff mbox series

Patch

diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index 8f6025acd10a..2b845ac51157 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -9,6 +9,7 @@ 
  *  Modified: 2004, Oct     Szabolcs Gyurko
  */
 
+#include <linux/cleanup.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/init.h>
@@ -756,10 +757,10 @@  int power_supply_get_battery_info(struct power_supply *psy,
 
 	for (index = 0; index < len; index++) {
 		struct power_supply_battery_ocv_table *table;
-		char *propname;
 		int i, tab_len, size;
 
-		propname = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d", index);
+		char *propname __free(kfree) = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d",
+							 index);
 		if (!propname) {
 			power_supply_put_battery_info(psy, info);
 			err = -ENOMEM;
@@ -768,13 +769,11 @@  int power_supply_get_battery_info(struct power_supply *psy,
 		list = of_get_property(battery_np, propname, &size);
 		if (!list || !size) {
 			dev_err(&psy->dev, "failed to get %s\n", propname);
-			kfree(propname);
 			power_supply_put_battery_info(psy, info);
 			err = -EINVAL;
 			goto out_put_node;
 		}
 
-		kfree(propname);
 		tab_len = size / (2 * sizeof(__be32));
 		info->ocv_table_size[index] = tab_len;