mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] power: supply: core: simplify with cleanup.h
@ 2024-07-05 11:31 Krzysztof Kozlowski
  2024-07-05 11:31 ` [PATCH 2/2] power: supply: twl4030_charger: correct comparision with old current Krzysztof Kozlowski
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Krzysztof Kozlowski @ 2024-07-05 11:31 UTC (permalink / raw)
  To: Sebastian Reichel, Nathan Chancellor, Nick Desaulniers,
	Bill Wendling, Justin Stitt, linux-pm, linux-kernel, llvm
  Cc: Krzysztof Kozlowski

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(-)

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;
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] power: supply: twl4030_charger: correct comparision with old current
  2024-07-05 11:31 [PATCH 1/2] power: supply: core: simplify with cleanup.h Krzysztof Kozlowski
@ 2024-07-05 11:31 ` Krzysztof Kozlowski
  2024-08-21 13:56 ` [PATCH 1/2] power: supply: core: simplify with cleanup.h Krzysztof Kozlowski
  2024-08-27 16:25 ` Sebastian Reichel
  2 siblings, 0 replies; 4+ messages in thread
From: Krzysztof Kozlowski @ 2024-07-05 11:31 UTC (permalink / raw)
  To: Sebastian Reichel, Nathan Chancellor, Nick Desaulniers,
	Bill Wendling, Justin Stitt, linux-pm, linux-kernel, llvm
  Cc: Krzysztof Kozlowski

Driver reads existing current value from two 8-bit registers, but then
compares only one of them with the new 16-bit value.  clang W=1 is also
not happy:

  twl4030_charger.c:243:16: error: variable 'cur_reg' set but not used [-Werror,-Wunused-but-set-variable]

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/power/supply/twl4030_charger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/supply/twl4030_charger.c b/drivers/power/supply/twl4030_charger.c
index 7b9b0b3e164e..f3f1a0862e93 100644
--- a/drivers/power/supply/twl4030_charger.c
+++ b/drivers/power/supply/twl4030_charger.c
@@ -363,7 +363,7 @@ static int twl4030_charger_update_current(struct twl4030_bci *bci)
 	if (status < 0)
 		return status;
 	cur_reg |= oldreg << 8;
-	if (reg != oldreg) {
+	if (reg != cur_reg) {
 		/* disable write protection for one write access for
 		 * BCIIREF */
 		status = twl_i2c_write_u8(TWL_MODULE_MAIN_CHARGE, 0xE7,
-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] power: supply: core: simplify with cleanup.h
  2024-07-05 11:31 [PATCH 1/2] power: supply: core: simplify with cleanup.h Krzysztof Kozlowski
  2024-07-05 11:31 ` [PATCH 2/2] power: supply: twl4030_charger: correct comparision with old current Krzysztof Kozlowski
@ 2024-08-21 13:56 ` Krzysztof Kozlowski
  2024-08-27 16:25 ` Sebastian Reichel
  2 siblings, 0 replies; 4+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-21 13:56 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: llvm, linux-kernel, Bill Wendling, Nathan Chancellor, linux-pm,
	Nick Desaulniers, Justin Stitt

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] power: supply: core: simplify with cleanup.h
  2024-07-05 11:31 [PATCH 1/2] power: supply: core: simplify with cleanup.h Krzysztof Kozlowski
  2024-07-05 11:31 ` [PATCH 2/2] power: supply: twl4030_charger: correct comparision with old current Krzysztof Kozlowski
  2024-08-21 13:56 ` [PATCH 1/2] power: supply: core: simplify with cleanup.h Krzysztof Kozlowski
@ 2024-08-27 16:25 ` Sebastian Reichel
  2 siblings, 0 replies; 4+ messages in thread
From: Sebastian Reichel @ 2024-08-27 16:25 UTC (permalink / raw)
  To: Sebastian Reichel, Nathan Chancellor, Nick Desaulniers,
	Bill Wendling, Justin Stitt, linux-pm, linux-kernel, llvm,
	Krzysztof Kozlowski


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,
-- 
Sebastian Reichel <sebastian.reichel@collabora.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-08-27 16:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-05 11:31 [PATCH 1/2] power: supply: core: simplify with cleanup.h Krzysztof Kozlowski
2024-07-05 11:31 ` [PATCH 2/2] power: supply: twl4030_charger: correct comparision with old current Krzysztof Kozlowski
2024-08-21 13:56 ` [PATCH 1/2] power: supply: core: simplify with cleanup.h Krzysztof Kozlowski
2024-08-27 16:25 ` Sebastian Reichel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®