Re: Re: [PATCH] tty/serial: Check for null pointer after calling devm_ioremap

From: Jiasheng Jiang
Date: Thu Jan 06 2022 - 20:42:34 EST


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