Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH -next] fsi: aspeed: Use devm_kfree in aspeed_master_release()
@ 2019-11-09  3:32 YueHaibing
  2019-11-09  3:36 ` [PATCH v2 " YueHaibing
  2019-11-11 14:16 ` [PATCH -next] fsi: aspeed: Use devm_kfree in aspeed_master_release() Guenter Roeck
  0 siblings, 2 replies; 5+ messages in thread
From: YueHaibing @ 2019-11-09  3:32 UTC (permalink / raw)
  To: jk, joel, eajames, andrew
  Cc: linux-aspeed, alistair, YueHaibing, linux-kernel, gregkh,
	linux-arm-kernel, linux-fsi

'aspeed' is allocted by devm_kfree(), it should not be
freed bt kfree().

Fixes: 1edac1269c02 ("fsi: Add ast2600 master driver")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 drivers/fsi/fsi-master-aspeed.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/fsi/fsi-master-aspeed.c b/drivers/fsi/fsi-master-aspeed.c
index 3dd82dd..0f63eec 100644
--- a/drivers/fsi/fsi-master-aspeed.c
+++ b/drivers/fsi/fsi-master-aspeed.c
@@ -361,7 +361,7 @@ static void aspeed_master_release(struct device *dev)
 	struct fsi_master_aspeed *aspeed =
 		to_fsi_master_aspeed(dev_to_fsi_master(dev));
 
-	kfree(aspeed);
+	devm_kfree(dev, aspeed);
 }
 
 /* mmode encoders */
-- 
2.7.4



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2 -next] fsi: aspeed: Use devm_kfree in aspeed_master_release()
  2019-11-09  3:32 [PATCH -next] fsi: aspeed: Use devm_kfree in aspeed_master_release() YueHaibing
@ 2019-11-09  3:36 ` " YueHaibing
  2019-11-11 14:17   ` Guenter Roeck
  2019-11-12  3:47   ` [PATCH v3 -next] fsi: aspeed: Fix aspeed device free YueHaibing
  2019-11-11 14:16 ` [PATCH -next] fsi: aspeed: Use devm_kfree in aspeed_master_release() Guenter Roeck
  1 sibling, 2 replies; 5+ messages in thread
From: YueHaibing @ 2019-11-09  3:36 UTC (permalink / raw)
  To: jk, joel, eajames, andrew
  Cc: linux-aspeed, alistair, YueHaibing, linux-kernel, gregkh,
	linux-arm-kernel, linux-fsi

'aspeed' is allocated by devm_kzalloc(), it should not be
freed by kfree().

Fixes: 1edac1269c02 ("fsi: Add ast2600 master driver")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
v2: fix log typos
---
 drivers/fsi/fsi-master-aspeed.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/fsi/fsi-master-aspeed.c b/drivers/fsi/fsi-master-aspeed.c
index 3dd82dd..0f63eec 100644
--- a/drivers/fsi/fsi-master-aspeed.c
+++ b/drivers/fsi/fsi-master-aspeed.c
@@ -361,7 +361,7 @@ static void aspeed_master_release(struct device *dev)
 	struct fsi_master_aspeed *aspeed =
 		to_fsi_master_aspeed(dev_to_fsi_master(dev));
 
-	kfree(aspeed);
+	devm_kfree(dev, aspeed);
 }
 
 /* mmode encoders */
-- 
2.7.4



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH -next] fsi: aspeed: Use devm_kfree in aspeed_master_release()
  2019-11-09  3:32 [PATCH -next] fsi: aspeed: Use devm_kfree in aspeed_master_release() YueHaibing
  2019-11-09  3:36 ` [PATCH v2 " YueHaibing
@ 2019-11-11 14:16 ` Guenter Roeck
  1 sibling, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2019-11-11 14:16 UTC (permalink / raw)
  To: YueHaibing, jk, joel, eajames, andrew
  Cc: linux-arm-kernel, alistair, linux-kernel, linux-aspeed, linux-fsi

On 11/8/19 7:32 PM, YueHaibing wrote:
> 'aspeed' is allocted by devm_kfree(), it should not be
> freed bt kfree().
> 
> Fixes: 1edac1269c02 ("fsi: Add ast2600 master driver")
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
>   drivers/fsi/fsi-master-aspeed.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/fsi/fsi-master-aspeed.c b/drivers/fsi/fsi-master-aspeed.c
> index 3dd82dd..0f63eec 100644
> --- a/drivers/fsi/fsi-master-aspeed.c
> +++ b/drivers/fsi/fsi-master-aspeed.c
> @@ -361,7 +361,7 @@ static void aspeed_master_release(struct device *dev)
>   	struct fsi_master_aspeed *aspeed =
>   		to_fsi_master_aspeed(dev_to_fsi_master(dev));
>   
> -	kfree(aspeed);
> +	devm_kfree(dev, aspeed);
>   }
>   
>   /* mmode encoders */
> 
The memory is attached to the device, and will thus be freed once the device
is released. Why is the release function needed in the first place ?

Guenter

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2 -next] fsi: aspeed: Use devm_kfree in aspeed_master_release()
  2019-11-09  3:36 ` [PATCH v2 " YueHaibing
@ 2019-11-11 14:17   ` Guenter Roeck
  2019-11-12  3:47   ` [PATCH v3 -next] fsi: aspeed: Fix aspeed device free YueHaibing
  1 sibling, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2019-11-11 14:17 UTC (permalink / raw)
  To: YueHaibing, jk, joel, eajames, andrew
  Cc: linux-arm-kernel, alistair, linux-kernel, linux-aspeed, linux-fsi

On 11/8/19 7:36 PM, YueHaibing wrote:
> 'aspeed' is allocated by devm_kzalloc(), it should not be
> freed by kfree().
> 
> Fixes: 1edac1269c02 ("fsi: Add ast2600 master driver")
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
> v2: fix log typos
> ---
>   drivers/fsi/fsi-master-aspeed.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/fsi/fsi-master-aspeed.c b/drivers/fsi/fsi-master-aspeed.c
> index 3dd82dd..0f63eec 100644
> --- a/drivers/fsi/fsi-master-aspeed.c
> +++ b/drivers/fsi/fsi-master-aspeed.c
> @@ -361,7 +361,7 @@ static void aspeed_master_release(struct device *dev)
>   	struct fsi_master_aspeed *aspeed =
>   		to_fsi_master_aspeed(dev_to_fsi_master(dev));
>   
> -	kfree(aspeed);
> +	devm_kfree(dev, aspeed);
>   }
>   
>   /* mmode encoders */
> 
Same question as before: Why is there a release function in the first place ?

Guenter


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v3 -next] fsi: aspeed: Fix aspeed device free
  2019-11-09  3:36 ` [PATCH v2 " YueHaibing
  2019-11-11 14:17   ` Guenter Roeck
@ 2019-11-12  3:47   ` YueHaibing
  1 sibling, 0 replies; 5+ messages in thread
From: YueHaibing @ 2019-11-12  3:47 UTC (permalink / raw)
  To: jk, joel, eajames, andrew, linux
  Cc: linux-aspeed, alistair, YueHaibing, linux-kernel,
	linux-arm-kernel, linux-fsi

'aspeed' is allocted by devm_kfree(), it should not be kfree().
In fact it will be freed while the device released.
Also we grap reference after fsi_master_register() success,
so should put it in fsi_master_aspeed_remove().

Fixes: 1edac1269c02 ("fsi: Add ast2600 master driver")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
v3: remove unneeded release() and put last reference
v2: fix log typos
---
 drivers/fsi/fsi-master-aspeed.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/fsi/fsi-master-aspeed.c b/drivers/fsi/fsi-master-aspeed.c
index f49742b..01a7f24 100644
--- a/drivers/fsi/fsi-master-aspeed.c
+++ b/drivers/fsi/fsi-master-aspeed.c
@@ -350,14 +350,6 @@ static int aspeed_master_break(struct fsi_master *master, int link)
 	return aspeed_master_write(master, link, 0, addr, &cmd, 4);
 }
 
-static void aspeed_master_release(struct device *dev)
-{
-	struct fsi_master_aspeed *aspeed =
-		to_fsi_master_aspeed(dev_to_fsi_master(dev));
-
-	kfree(aspeed);
-}
-
 /* mmode encoders */
 static inline u32 fsi_mmode_crs0(u32 x)
 {
@@ -483,7 +475,6 @@ static int fsi_master_aspeed_probe(struct platform_device *pdev)
 	dev_info(&pdev->dev, "hub version %08x (%d links)\n", reg, links);
 
 	aspeed->master.dev.parent = &pdev->dev;
-	aspeed->master.dev.release = aspeed_master_release;
 	aspeed->master.dev.of_node = of_node_get(dev_of_node(&pdev->dev));
 
 	aspeed->master.n_links = links;
@@ -522,6 +513,7 @@ static int fsi_master_aspeed_remove(struct platform_device *pdev)
 
 	fsi_master_unregister(&aspeed->master);
 	clk_disable_unprepare(aspeed->clk);
+	put_device(&aspeed->master.dev);
 
 	return 0;
 }
-- 
2.7.4



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-09  3:32 [PATCH -next] fsi: aspeed: Use devm_kfree in aspeed_master_release() YueHaibing
2019-11-09  3:36 ` [PATCH v2 " YueHaibing
2019-11-11 14:17   ` Guenter Roeck
2019-11-12  3:47   ` [PATCH v3 -next] fsi: aspeed: Fix aspeed device free YueHaibing
2019-11-11 14:16 ` [PATCH -next] fsi: aspeed: Use devm_kfree in aspeed_master_release() Guenter Roeck

Linux-ARM-Kernel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/0 linux-arm-kernel/git/0.git
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/1 linux-arm-kernel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-arm-kernel linux-arm-kernel/ https://lore.kernel.org/linux-arm-kernel \
		linux-arm-kernel@lists.infradead.org
	public-inbox-index linux-arm-kernel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-arm-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git