Re: [PATCH net] ice: Add check for kzalloc
From: Jiasheng Jiang
Date: Tue Dec 06 2022 - 21:20:52 EST
On Tue, Dec 06, 2022 at 05:47:01PM +0800, Jiri Pirko wrote:
>>As kzalloc may fail and return NULL pointer,
>>it should be better to check the return value
>>in order to avoid the NULL pointer dereference.
>
> Okay, so? Be imperative to the code base, tell it what to do in your
> patch description.
OK, I will describe the changes by the patch in more details.
>>@@ -462,6 +462,17 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf)
>> GFP_KERNEL);
>> pf->gnss_serial[i] = NULL;
>>
>>+ if (!pf->gnss_tty_port[i]) {
>>+ for (j = 0; j < i; j++) {
>>+ tty_port_destroy(pf->gnss_tty_port[j]);
>
> You are destroying port which you didn't call (pf->gnss_tty_port[i])
> for. Also, you are introducing a code duplication here with the error
> path couple of lines below. Please convert this to goto-label error
> path so the cleanup code is shared.
I will convert this to goto-label in v2.
But I have a question that the j is from 0 to (i - 1), and therefore only
the initialized port will be destroyed.
Is there any wrong?
Thanks,
Jiang