linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: Re: [PATCH] tty/serial: Check for null pointer after calling devm_ioremap
@ 2022-01-07  1:42 Jiasheng Jiang
  0 siblings, 0 replies; 2+ messages in thread
From: Jiasheng Jiang @ 2022-01-07  1:42 UTC (permalink / raw)
  To: gregkh; +Cc: jirislaby, linux-serial, linux-kernel, Jiasheng Jiang

On Thu, Jan 06, 2022 at 11:01:20PM +0800, Greg KH wrote:
>> As the possible failure of the allocation, the devm_ioremap() may return
>> NULL pointer.
>
> I do not understand this sentence.

Well, since the devm_ioremap() calls devres_alloc() to allocate memory,
it may fail because of the lack of memory and return NULL pointer.

>> And the 'port->membase' will be directly used in mlb_usio_startup().
>
> This does not make sense either.

I notice that in mlb_usio_startup() 'port->membase' is used in
'escr = readb(port->membase + MLB_USIO_REG_ESCR);'
without checking whether it is NULL before, that is to say, it is directly used.
Therefore, it may cause the dereference of the NULL pointer.

>> Therefore, in order to avoid the dereference of the NULL pointer, it
>> should be better to add the sanity check.
>
> What do you mean by "sanity check"?

Since I believe that after all the allocation we need to check whether it
succeed.
So the "sanity check" means the check that lost and we need to make up to
maintain the integrity.

Moreover, I am glad for your reply.
And I will refine my commit message in next version to make it more clear.

Sincerely thanks,
Jiang


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

* Re: Re: [PATCH] tty/serial: Check for null pointer after calling devm_ioremap
@ 2022-01-13  8:02 Jiasheng Jiang
  0 siblings, 0 replies; 2+ messages in thread
From: Jiasheng Jiang @ 2022-01-13  8:02 UTC (permalink / raw)
  To: jirislaby, gregkh; +Cc: linux-serial, linux-kernel, Jiasheng Jiang

On Thu, Jan 13, 2022 at 03:35:14PM +0800, Jiri Slaby wrote:
>> diff --git a/drivers/tty/serial/milbeaut_usio.c b/drivers/tty/serial/milbeaut_usio.c
>> index 8f2cab7f66ad..1ecbf6d0dc79 100644
>> --- a/drivers/tty/serial/milbeaut_usio.c
>> +++ b/drivers/tty/serial/milbeaut_usio.c
>> @@ -523,6 +523,10 @@ static int mlb_usio_probe(struct platform_device *pdev)
>>   	}
>>   	port->membase = devm_ioremap(&pdev->dev, res->start,
>>   				resource_size(res));
>> +	if (!port->membase) {
>> +		ret = -ENOMEM;
>> +		goto failed;
>> +	}
>
> what about using devm_ioremap_resource() and have only one if there?

Well, I check the comment of the devm_ioremap_resource() and notice that
it checks and requests region before ioremap.
And the usage example is fit for the situation.
But I have still have no idea what the concrete advantages of the
devm_ioremap_resource(), like fixing something or improve the efficiency.
Please give me more detail.

Sincerely thanks,
Jiang


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

end of thread, other threads:[~2022-01-13  8:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-07  1:42 Re: [PATCH] tty/serial: Check for null pointer after calling devm_ioremap Jiasheng Jiang
2022-01-13  8:02 Jiasheng Jiang

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