diff mbox series

ice: Fix some null pointer dereference issues in ice_ptp.c

Message ID 20231211062649.247148-1-chentao@kylinos.cn (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series ice: Fix some null pointer dereference issues in ice_ptp.c | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1115 this patch: 1115
netdev/cc_maintainers success CCed 11 of 11 maintainers
netdev/build_clang success Errors and warnings before: 1142 this patch: 1142
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1142 this patch: 1142
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Kunwu Chan Dec. 11, 2023, 6:26 a.m. UTC
devm_kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure.

Fixes: d938a8cca88a ("ice: Auxbus devices & driver for E822 TS")
Cc: Kunwu Chan <kunwu.chan@hotmail.com>
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 drivers/net/ethernet/intel/ice/ice_ptp.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Przemek Kitszel Dec. 11, 2023, 7:15 a.m. UTC | #1
On 12/11/23 07:26, Kunwu Chan wrote:
> devm_kasprintf() returns a pointer to dynamically allocated memory
> which can be NULL upon failure.
> 
> Fixes: d938a8cca88a ("ice: Auxbus devices & driver for E822 TS")
> Cc: Kunwu Chan <kunwu.chan@hotmail.com>
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>

I would suggest adding "iwl-net" as a target here

> ---
>   drivers/net/ethernet/intel/ice/ice_ptp.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c
> index 1eddcbe89b0c..59794ce4f243 100644
> --- a/drivers/net/ethernet/intel/ice/ice_ptp.c
> +++ b/drivers/net/ethernet/intel/ice/ice_ptp.c
> @@ -2668,6 +2668,8 @@ static int ice_ptp_register_auxbus_driver(struct ice_pf *pf)
>   	name = devm_kasprintf(dev, GFP_KERNEL, "ptp_aux_dev_%u_%u_clk%u",
>   			      pf->pdev->bus->number, PCI_SLOT(pf->pdev->devfn),
>   			      ice_get_ptp_src_clock_index(&pf->hw));
> +	if (!name)
> +		return -ENOMEM;
>   
>   	aux_driver->name = name;
>   	aux_driver->shutdown = ice_ptp_auxbus_shutdown;
> @@ -2929,6 +2931,10 @@ static int ice_ptp_create_auxbus_device(struct ice_pf *pf)
>   	name = devm_kasprintf(dev, GFP_KERNEL, "ptp_aux_dev_%u_%u_clk%u",
>   			      pf->pdev->bus->number, PCI_SLOT(pf->pdev->devfn),
>   			      ice_get_ptp_src_clock_index(&pf->hw));
> +	if (!name) {
> +		dev_err(dev, "Failed to allocate memory\n");

Kuba @ [1]:
no warnings on allocation failures, there will be a splat for GFP_KERNEL
(checkpatch should catch this)

[1] https://lore.kernel.org/netdev/20231206195304.6226771d@kernel.org/T/

so just "return -ENOMEM" would be sufficient

> +		return -ENOMEM;
> +	}
>   
>   	aux_dev->name = name;
>   	aux_dev->id = id;

I didn't checked but having same code in two places raises questions.
Are you overwriting old name here, or our code is just self similar?
Kunwu Chan Dec. 11, 2023, 9:32 a.m. UTC | #2
Thanks for your suggestion.

I made the patch based on linux-next.git(tag:next-20231211).

Our code is just self-similar, i didn't override the old name.
I keep the logic as it was before.
The newest code is:

https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/net/ethernet/intel/ice/ice_ptp.c#n2747

https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/net/ethernet/intel/ice/ice_ptp.c#n2993

I'll update v2 patch with:
1. update suject prefix to "[PATCH v2 iwl-next]"
2. remove 'dev_err'


Thanks again,
Kunwu

On 2023/12/11 15:15, Przemek Kitszel wrote:
> On 12/11/23 07:26, Kunwu Chan wrote:
>> devm_kasprintf() returns a pointer to dynamically allocated memory
>> which can be NULL upon failure.
>>
>> Fixes: d938a8cca88a ("ice: Auxbus devices & driver for E822 TS")
>> Cc: Kunwu Chan <kunwu.chan@hotmail.com>
>> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> 
> I would suggest adding "iwl-net" as a target here
> 
>> ---
>>   drivers/net/ethernet/intel/ice/ice_ptp.c | 6 ++++++
>>   1 file changed, 6 insertions(+)
>>
>> diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c 
>> b/drivers/net/ethernet/intel/ice/ice_ptp.c
>> index 1eddcbe89b0c..59794ce4f243 100644
>> --- a/drivers/net/ethernet/intel/ice/ice_ptp.c
>> +++ b/drivers/net/ethernet/intel/ice/ice_ptp.c
>> @@ -2668,6 +2668,8 @@ static int ice_ptp_register_auxbus_driver(struct 
>> ice_pf *pf)
>>       name = devm_kasprintf(dev, GFP_KERNEL, "ptp_aux_dev_%u_%u_clk%u",
>>                     pf->pdev->bus->number, PCI_SLOT(pf->pdev->devfn),
>>                     ice_get_ptp_src_clock_index(&pf->hw));
>> +    if (!name)
>> +        return -ENOMEM;
>>       aux_driver->name = name;
>>       aux_driver->shutdown = ice_ptp_auxbus_shutdown;
>> @@ -2929,6 +2931,10 @@ static int ice_ptp_create_auxbus_device(struct 
>> ice_pf *pf)
>>       name = devm_kasprintf(dev, GFP_KERNEL, "ptp_aux_dev_%u_%u_clk%u",
>>                     pf->pdev->bus->number, PCI_SLOT(pf->pdev->devfn),
>>                     ice_get_ptp_src_clock_index(&pf->hw));
>> +    if (!name) {
>> +        dev_err(dev, "Failed to allocate memory\n");
> 
> Kuba @ [1]:
> no warnings on allocation failures, there will be a splat for GFP_KERNEL
> (checkpatch should catch this)
> 
> [1] https://lore.kernel.org/netdev/20231206195304.6226771d@kernel.org/T/
> 
> so just "return -ENOMEM" would be sufficient
> 
>> +        return -ENOMEM;
>> +    }
>>       aux_dev->name = name;
>>       aux_dev->id = id;
> 
> I didn't checked but having same code in two places raises questions.
> Are you overwriting old name here, or our code is just self similar?
Przemek Kitszel Dec. 11, 2023, 10:12 a.m. UTC | #3
On 12/11/23 10:32, Kunwu Chan wrote:
> Thanks for your suggestion.
> 
> I made the patch based on linux-next.git(tag:next-20231211).
> 
> Our code is just self-similar, i didn't override the old name.
> I keep the logic as it was before.
> The newest code is:
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/net/ethernet/intel/ice/ice_ptp.c#n2747
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/drivers/net/ethernet/intel/ice/ice_ptp.c#n2993
> 

sure, I just checked those, no huge benefit of dedup

> I'll update v2 patch with:
> 1. update suject prefix to "[PATCH v2 iwl-next]"
> 2. remove 'dev_err'
> 
> 
> Thanks again,
> Kunwu

Thank you too

> 
> On 2023/12/11 15:15, Przemek Kitszel wrote:
>> On 12/11/23 07:26, Kunwu Chan wrote:
>>> devm_kasprintf() returns a pointer to dynamically allocated memory
>>> which can be NULL upon failure.
>>>
>>> Fixes: d938a8cca88a ("ice: Auxbus devices & driver for E822 TS")
>>> Cc: Kunwu Chan <kunwu.chan@hotmail.com>
>>> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
>>
>> I would suggest adding "iwl-net" as a target here
>>
>>> ---
>>>   drivers/net/ethernet/intel/ice/ice_ptp.c | 6 ++++++
>>>   1 file changed, 6 insertions(+)
>>>
>>> diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c 
>>> b/drivers/net/ethernet/intel/ice/ice_ptp.c
>>> index 1eddcbe89b0c..59794ce4f243 100644
>>> --- a/drivers/net/ethernet/intel/ice/ice_ptp.c
>>> +++ b/drivers/net/ethernet/intel/ice/ice_ptp.c
>>> @@ -2668,6 +2668,8 @@ static int 
>>> ice_ptp_register_auxbus_driver(struct ice_pf *pf)
>>>       name = devm_kasprintf(dev, GFP_KERNEL, "ptp_aux_dev_%u_%u_clk%u",
>>>                     pf->pdev->bus->number, PCI_SLOT(pf->pdev->devfn),
>>>                     ice_get_ptp_src_clock_index(&pf->hw));
>>> +    if (!name)
>>> +        return -ENOMEM;
>>>       aux_driver->name = name;
>>>       aux_driver->shutdown = ice_ptp_auxbus_shutdown;
>>> @@ -2929,6 +2931,10 @@ static int ice_ptp_create_auxbus_device(struct 
>>> ice_pf *pf)
>>>       name = devm_kasprintf(dev, GFP_KERNEL, "ptp_aux_dev_%u_%u_clk%u",
>>>                     pf->pdev->bus->number, PCI_SLOT(pf->pdev->devfn),
>>>                     ice_get_ptp_src_clock_index(&pf->hw));
>>> +    if (!name) {
>>> +        dev_err(dev, "Failed to allocate memory\n");
>>
>> Kuba @ [1]:
>> no warnings on allocation failures, there will be a splat for GFP_KERNEL
>> (checkpatch should catch this)
>>
>> [1] https://lore.kernel.org/netdev/20231206195304.6226771d@kernel.org/T/
>>
>> so just "return -ENOMEM" would be sufficient
>>
>>> +        return -ENOMEM;
>>> +    }
>>>       aux_dev->name = name;
>>>       aux_dev->id = id;
>>
>> I didn't checked but having same code in two places raises questions.
>> Are you overwriting old name here, or our code is just self similar?
>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c
index 1eddcbe89b0c..59794ce4f243 100644
--- a/drivers/net/ethernet/intel/ice/ice_ptp.c
+++ b/drivers/net/ethernet/intel/ice/ice_ptp.c
@@ -2668,6 +2668,8 @@  static int ice_ptp_register_auxbus_driver(struct ice_pf *pf)
 	name = devm_kasprintf(dev, GFP_KERNEL, "ptp_aux_dev_%u_%u_clk%u",
 			      pf->pdev->bus->number, PCI_SLOT(pf->pdev->devfn),
 			      ice_get_ptp_src_clock_index(&pf->hw));
+	if (!name)
+		return -ENOMEM;
 
 	aux_driver->name = name;
 	aux_driver->shutdown = ice_ptp_auxbus_shutdown;
@@ -2929,6 +2931,10 @@  static int ice_ptp_create_auxbus_device(struct ice_pf *pf)
 	name = devm_kasprintf(dev, GFP_KERNEL, "ptp_aux_dev_%u_%u_clk%u",
 			      pf->pdev->bus->number, PCI_SLOT(pf->pdev->devfn),
 			      ice_get_ptp_src_clock_index(&pf->hw));
+	if (!name) {
+		dev_err(dev, "Failed to allocate memory\n");
+		return -ENOMEM;
+	}
 
 	aux_dev->name = name;
 	aux_dev->id = id;