linux-mediatek.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] mfd: mt6360: Simplify with cleanup.h
@ 2024-07-07 11:48 Krzysztof Kozlowski
  2024-07-07 11:48 ` [PATCH 2/2] mfd: syscon: " Krzysztof Kozlowski
  2024-07-25  7:50 ` [PATCH 1/2] mfd: mt6360: " Lee Jones
  0 siblings, 2 replies; 5+ messages in thread
From: Krzysztof Kozlowski @ 2024-07-07 11:48 UTC (permalink / raw)
  To: Lee Jones, Matthias Brugger, AngeloGioacchino Del Regno,
	Arnd Bergmann, linux-kernel, linux-arm-kernel, linux-mediatek
  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/mfd/mt6360-core.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/drivers/mfd/mt6360-core.c b/drivers/mfd/mt6360-core.c
index 2685efa5c9e2..b9b1036c8ff4 100644
--- a/drivers/mfd/mt6360-core.c
+++ b/drivers/mfd/mt6360-core.c
@@ -5,6 +5,7 @@
  * Author: Gene Chen <gene_chen@richtek.com>
  */
 
+#include <linux/cleanup.h>
 #include <linux/crc8.h>
 #include <linux/i2c.h>
 #include <linux/init.h>
@@ -404,7 +405,6 @@ static int mt6360_regmap_read(void *context, const void *reg, size_t reg_size,
 	u8 reg_addr = *(u8 *)(reg + 1);
 	struct i2c_client *i2c;
 	bool crc_needed = false;
-	u8 *buf;
 	int buf_len = MT6360_ALLOC_READ_SIZE(val_size);
 	int read_size = val_size;
 	u8 crc;
@@ -423,7 +423,7 @@ static int mt6360_regmap_read(void *context, const void *reg, size_t reg_size,
 		read_size += MT6360_CRC_CRC8_SIZE;
 	}
 
-	buf = kzalloc(buf_len, GFP_KERNEL);
+	u8 *buf __free(kfree) = kzalloc(buf_len, GFP_KERNEL);
 	if (!buf)
 		return -ENOMEM;
 
@@ -433,24 +433,19 @@ static int mt6360_regmap_read(void *context, const void *reg, size_t reg_size,
 	ret = i2c_smbus_read_i2c_block_data(i2c, reg_addr, read_size,
 					    buf + MT6360_CRC_PREDATA_OFFSET);
 	if (ret < 0)
-		goto out;
-	else if (ret != read_size) {
-		ret = -EIO;
-		goto out;
-	}
+		return ret;
+	else if (ret != read_size)
+		return -EIO;
 
 	if (crc_needed) {
 		crc = crc8(ddata->crc8_tbl, buf, val_size + MT6360_CRC_PREDATA_OFFSET, 0);
-		if (crc != buf[val_size + MT6360_CRC_PREDATA_OFFSET]) {
-			ret = -EIO;
-			goto out;
-		}
+		if (crc != buf[val_size + MT6360_CRC_PREDATA_OFFSET])
+			return -EIO;
 	}
 
 	memcpy(val, buf + MT6360_CRC_PREDATA_OFFSET, val_size);
-out:
-	kfree(buf);
-	return (ret < 0) ? ret : 0;
+
+	return 0;
 }
 
 static int mt6360_regmap_write(void *context, const void *val, size_t val_size)
-- 
2.43.0



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

* [PATCH 2/2] mfd: syscon: Simplify with cleanup.h
  2024-07-07 11:48 [PATCH 1/2] mfd: mt6360: Simplify with cleanup.h Krzysztof Kozlowski
@ 2024-07-07 11:48 ` Krzysztof Kozlowski
  2024-07-25  7:50   ` (subset) " Lee Jones
  2024-07-25  7:50 ` [PATCH 1/2] mfd: mt6360: " Lee Jones
  1 sibling, 1 reply; 5+ messages in thread
From: Krzysztof Kozlowski @ 2024-07-07 11:48 UTC (permalink / raw)
  To: Lee Jones, Matthias Brugger, AngeloGioacchino Del Regno,
	Arnd Bergmann, linux-kernel, linux-arm-kernel, linux-mediatek
  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/mfd/syscon.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
index 7d0e91164cba..c939a76e83b8 100644
--- a/drivers/mfd/syscon.c
+++ b/drivers/mfd/syscon.c
@@ -8,6 +8,7 @@
  * Author: Dong Aisheng <dong.aisheng@linaro.org>
  */
 
+#include <linux/cleanup.h>
 #include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/hwspinlock.h>
@@ -45,7 +46,6 @@ static const struct regmap_config syscon_regmap_config = {
 static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
 {
 	struct clk *clk;
-	struct syscon *syscon;
 	struct regmap *regmap;
 	void __iomem *base;
 	u32 reg_io_width;
@@ -54,20 +54,16 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
 	struct resource res;
 	struct reset_control *reset;
 
-	syscon = kzalloc(sizeof(*syscon), GFP_KERNEL);
+	struct syscon *syscon __free(kfree) = kzalloc(sizeof(*syscon), GFP_KERNEL);
 	if (!syscon)
 		return ERR_PTR(-ENOMEM);
 
-	if (of_address_to_resource(np, 0, &res)) {
-		ret = -ENOMEM;
-		goto err_map;
-	}
+	if (of_address_to_resource(np, 0, &res))
+		return ERR_PTR(-ENOMEM);
 
 	base = of_iomap(np, 0);
-	if (!base) {
-		ret = -ENOMEM;
-		goto err_map;
-	}
+	if (!base)
+		return ERR_PTR(-ENOMEM);
 
 	/* Parse the device's DT node for an endianness specification */
 	if (of_property_read_bool(np, "big-endian"))
@@ -152,7 +148,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
 	list_add_tail(&syscon->list, &syscon_list);
 	spin_unlock(&syscon_list_slock);
 
-	return syscon;
+	return_ptr(syscon);
 
 err_reset:
 	reset_control_put(reset);
@@ -163,8 +159,6 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
 	regmap_exit(regmap);
 err_regmap:
 	iounmap(base);
-err_map:
-	kfree(syscon);
 	return ERR_PTR(ret);
 }
 
-- 
2.43.0



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

* Re: (subset) [PATCH 2/2] mfd: syscon: Simplify with cleanup.h
  2024-07-07 11:48 ` [PATCH 2/2] mfd: syscon: " Krzysztof Kozlowski
@ 2024-07-25  7:50   ` Lee Jones
  0 siblings, 0 replies; 5+ messages in thread
From: Lee Jones @ 2024-07-25  7:50 UTC (permalink / raw)
  To: Lee Jones, Matthias Brugger, AngeloGioacchino Del Regno,
	Arnd Bergmann, linux-kernel, linux-arm-kernel, linux-mediatek,
	Krzysztof Kozlowski

On Sun, 07 Jul 2024 13:48:23 +0200, Krzysztof Kozlowski wrote:
> Allocate the memory with scoped/cleanup.h to reduce error handling and
> make the code a bit simpler.
> 
> 

Applied, thanks!

[2/2] mfd: syscon: Simplify with cleanup.h
      commit: c80c7dfec9d8514f1fcc34402124026e59d2e2cb

--
Lee Jones [李琼斯]



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

* Re: [PATCH 1/2] mfd: mt6360: Simplify with cleanup.h
  2024-07-07 11:48 [PATCH 1/2] mfd: mt6360: Simplify with cleanup.h Krzysztof Kozlowski
  2024-07-07 11:48 ` [PATCH 2/2] mfd: syscon: " Krzysztof Kozlowski
@ 2024-07-25  7:50 ` Lee Jones
  2024-07-25  7:52   ` Lee Jones
  1 sibling, 1 reply; 5+ messages in thread
From: Lee Jones @ 2024-07-25  7:50 UTC (permalink / raw)
  To: Lee Jones, Matthias Brugger, AngeloGioacchino Del Regno,
	Arnd Bergmann, linux-kernel, linux-arm-kernel, linux-mediatek,
	Krzysztof Kozlowski

On Sun, 07 Jul 2024 13:48:22 +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] mfd: mt6360: Simplify with cleanup.h
      commit: 05dd1b4a8d71b5c422bff8bf6ad22baf5722c2a2
[2/2] mfd: syscon: Simplify with cleanup.h
      commit: c80c7dfec9d8514f1fcc34402124026e59d2e2cb

--
Lee Jones [李琼斯]



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

* Re: [PATCH 1/2] mfd: mt6360: Simplify with cleanup.h
  2024-07-25  7:50 ` [PATCH 1/2] mfd: mt6360: " Lee Jones
@ 2024-07-25  7:52   ` Lee Jones
  0 siblings, 0 replies; 5+ messages in thread
From: Lee Jones @ 2024-07-25  7:52 UTC (permalink / raw)
  To: Matthias Brugger, AngeloGioacchino Del Regno, Arnd Bergmann,
	linux-kernel, linux-arm-kernel, linux-mediatek,
	Krzysztof Kozlowski

On Thu, 25 Jul 2024, Lee Jones wrote:

> On Sun, 07 Jul 2024 13:48:22 +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] mfd: mt6360: Simplify with cleanup.h
>       commit: 05dd1b4a8d71b5c422bff8bf6ad22baf5722c2a2
> [2/2] mfd: syscon: Simplify with cleanup.h
>       commit: c80c7dfec9d8514f1fcc34402124026e59d2e2cb

Not keen on using the includes filename as a description.

Changed the subject lines of both of these to:

  "Use scoped variables with memory allocators to simplify error paths"

-- 
Lee Jones [李琼斯]


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

end of thread, other threads:[~2024-07-25  7:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-07 11:48 [PATCH 1/2] mfd: mt6360: Simplify with cleanup.h Krzysztof Kozlowski
2024-07-07 11:48 ` [PATCH 2/2] mfd: syscon: " Krzysztof Kozlowski
2024-07-25  7:50   ` (subset) " Lee Jones
2024-07-25  7:50 ` [PATCH 1/2] mfd: mt6360: " Lee Jones
2024-07-25  7:52   ` Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).