linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bus: hisi_lpc: Don't use devm_kzalloc() to allocate logical PIO range
@ 2019-06-14  9:47 John Garry
  2019-06-14 10:04 ` Joe Perches
  0 siblings, 1 reply; 3+ messages in thread
From: John Garry @ 2019-06-14  9:47 UTC (permalink / raw)
  To: xuwei5; +Cc: bhelgaas, linuxarm, arm, linux-kernel, John Garry

If, after registering a logical PIO range, the driver probe later fails,
the logical PIO range memory will be released automatically.

This causes an issue, in that the logical PIO range is not unregistered
(that is not supported) and the released range memory may be later
referenced

Allocate the logical PIO range with kzalloc() to avoid this potential
issue.

Fixes: adf38bb0b5956 ("HISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings")
Signed-off-by: John Garry <john.garry@huawei.com>

diff --git a/drivers/bus/hisi_lpc.c b/drivers/bus/hisi_lpc.c
index 19d7b6ff2f17..d9ab4e76010d 100644
--- a/drivers/bus/hisi_lpc.c
+++ b/drivers/bus/hisi_lpc.c
@@ -599,7 +599,7 @@ static int hisi_lpc_probe(struct platform_device *pdev)
 	if (IS_ERR(lpcdev->membase))
 		return PTR_ERR(lpcdev->membase);
 
-	range = devm_kzalloc(dev, sizeof(*range), GFP_KERNEL);
+	range = kzalloc(sizeof(*range), GFP_KERNEL);
 	if (!range)
 		return -ENOMEM;
 
@@ -610,6 +610,7 @@ static int hisi_lpc_probe(struct platform_device *pdev)
 	ret = logic_pio_register_range(range);
 	if (ret) {
 		dev_err(dev, "register IO range failed (%d)!\n", ret);
+		kfree(range);
 		return ret;
 	}
 	lpcdev->io_host = range;
-- 
2.17.1


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

* Re: [PATCH] bus: hisi_lpc: Don't use devm_kzalloc() to allocate logical PIO range
  2019-06-14  9:47 [PATCH] bus: hisi_lpc: Don't use devm_kzalloc() to allocate logical PIO range John Garry
@ 2019-06-14 10:04 ` Joe Perches
  2019-06-14 10:07   ` John Garry
  0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2019-06-14 10:04 UTC (permalink / raw)
  To: John Garry, xuwei5; +Cc: bhelgaas, linuxarm, arm, linux-kernel

On Fri, 2019-06-14 at 17:47 +0800, John Garry wrote:
> If, after registering a logical PIO range, the driver probe later fails,
> the logical PIO range memory will be released automatically.
> 
> This causes an issue, in that the logical PIO range is not unregistered
> (that is not supported) and the released range memory may be later
> referenced
> 
> Allocate the logical PIO range with kzalloc() to avoid this potential
> issue.
> 
> Fixes: adf38bb0b5956 ("HISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings")
> Signed-off-by: John Garry <john.garry@huawei.com>
> 
> diff --git a/drivers/bus/hisi_lpc.c b/drivers/bus/hisi_lpc.c
[]
> @@ -599,7 +599,7 @@ static int hisi_lpc_probe(struct platform_device *pdev)
>  	if (IS_ERR(lpcdev->membase))
>  		return PTR_ERR(lpcdev->membase);
>  
> -	range = devm_kzalloc(dev, sizeof(*range), GFP_KERNEL);
> +	range = kzalloc(sizeof(*range), GFP_KERNEL);

If this is really necessary, it'd be useful to say so in the
code too with a comment so it doesn't get drive-by 'unfixed'
by someone well meaning but ill-uninformed.



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

* Re: [PATCH] bus: hisi_lpc: Don't use devm_kzalloc() to allocate logical PIO range
  2019-06-14 10:04 ` Joe Perches
@ 2019-06-14 10:07   ` John Garry
  0 siblings, 0 replies; 3+ messages in thread
From: John Garry @ 2019-06-14 10:07 UTC (permalink / raw)
  To: Joe Perches, xuwei5; +Cc: bhelgaas, linuxarm, arm, linux-kernel

On 14/06/2019 11:04, Joe Perches wrote:
> On Fri, 2019-06-14 at 17:47 +0800, John Garry wrote:
>> If, after registering a logical PIO range, the driver probe later fails,
>> the logical PIO range memory will be released automatically.
>>
>> This causes an issue, in that the logical PIO range is not unregistered
>> (that is not supported) and the released range memory may be later
>> referenced
>>
>> Allocate the logical PIO range with kzalloc() to avoid this potential
>> issue.
>>
>> Fixes: adf38bb0b5956 ("HISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings")
>> Signed-off-by: John Garry <john.garry@huawei.com>
>>
>> diff --git a/drivers/bus/hisi_lpc.c b/drivers/bus/hisi_lpc.c
> []
>> @@ -599,7 +599,7 @@ static int hisi_lpc_probe(struct platform_device *pdev)
>>  	if (IS_ERR(lpcdev->membase))
>>  		return PTR_ERR(lpcdev->membase);
>>
>> -	range = devm_kzalloc(dev, sizeof(*range), GFP_KERNEL);
>> +	range = kzalloc(sizeof(*range), GFP_KERNEL);
>
> If this is really necessary, it'd be useful to say so in the
> code too with a comment so it doesn't get drive-by 'unfixed'
> by someone well meaning but ill-uninformed.

OK, fine. I can do that.

Cheers,
John

>
>
>
> .
>



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

end of thread, other threads:[~2019-06-14 10:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-14  9:47 [PATCH] bus: hisi_lpc: Don't use devm_kzalloc() to allocate logical PIO range John Garry
2019-06-14 10:04 ` Joe Perches
2019-06-14 10:07   ` John Garry

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