diff mbox series

net: dsa: vsc73xx: Add null pointer check to vsc73xx_gpio_probe

Message ID 20231211024549.231417-1-chentao@kylinos.cn (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: dsa: vsc73xx: Add null pointer check to vsc73xx_gpio_probe | 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 7 of 7 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 No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1142 this patch: 1142
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 10 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 Dec. 11, 2023, 2:45 a.m. UTC
devm_kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure.

Cc: Kunwu Chan <kunwu.chan@hotmail.com>
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 drivers/net/dsa/vitesse-vsc73xx-core.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Jakub Kicinski Dec. 12, 2023, 9:27 p.m. UTC | #1
On Mon, 11 Dec 2023 10:45:49 +0800 Kunwu Chan wrote:
>  	vsc->gc.label = devm_kasprintf(vsc->dev, GFP_KERNEL, "VSC%04x",
>  				       vsc->chipid);
> +	if (!vsc->gc.label) {
> +		dev_err(vsc->dev, "Fail to allocate memory\n");
> +		return -ENOMEM;
> +	}

Don't add error prints on memory allocations.
There will be an OOM splat in the logs.
Kunwu Dec. 14, 2023, 3:22 a.m. UTC | #2
Thanks for your reply.

I'll remove 'dev_err' in v2 patch.

Thanks again.

On 2023/12/13 05:27, Jakub Kicinski wrote:
> On Mon, 11 Dec 2023 10:45:49 +0800 Kunwu Chan wrote:
>>   	vsc->gc.label = devm_kasprintf(vsc->dev, GFP_KERNEL, "VSC%04x",
>>   				       vsc->chipid);
>> +	if (!vsc->gc.label) {
>> +		dev_err(vsc->dev, "Fail to allocate memory\n");
>> +		return -ENOMEM;
>> +	}
> 
> Don't add error prints on memory allocations.
> There will be an OOM splat in the logs.
diff mbox series

Patch

diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c
index e6f29e4e508c..f136eb5aea69 100644
--- a/drivers/net/dsa/vitesse-vsc73xx-core.c
+++ b/drivers/net/dsa/vitesse-vsc73xx-core.c
@@ -1135,6 +1135,10 @@  static int vsc73xx_gpio_probe(struct vsc73xx *vsc)
 
 	vsc->gc.label = devm_kasprintf(vsc->dev, GFP_KERNEL, "VSC%04x",
 				       vsc->chipid);
+	if (!vsc->gc.label) {
+		dev_err(vsc->dev, "Fail to allocate memory\n");
+		return -ENOMEM;
+	}
 	vsc->gc.ngpio = 4;
 	vsc->gc.owner = THIS_MODULE;
 	vsc->gc.parent = vsc->dev;