Re: [PATCH] Fix possible NULL Pointer Dereference in 'extcon_rtk_type_c_probe'
From: Markus Elfring
Date: Mon Sep 30 2024 - 11:29:45 EST
> A 'devm_kzalloc' in 'extcon_rtk_type_c_probe' could possibly return null pointer.
> Add a null check for the returned pointer.
How do you think about a wording variant like the following?
A devm_kzalloc() call can fail in this function implementation.
Thus add a null pointer check and corresponding exception handling
for the data structure member “type_c_cfg”.
…
> Signed-off-by: Zichen Xie <zichenxie0106@xxxxxxxxx>
> Reported-by: Zichen Xie <zichenxie0106@xxxxxxxxx>
…
How good does such a tag combination fit together for the same person?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.11#n525
Can a subject like “[PATCH] extcon: realtek: Prevent null pointer dereference in extcon_rtk_type_c_probe()”
be more appropriate?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.11#n613
…
> +++ b/drivers/extcon/extcon-rtk-type-c.c
> @@ -1371,6 +1371,12 @@ static int extcon_rtk_type_c_probe(struct platform_device *pdev)
>
> type_c->type_c_cfg = devm_kzalloc(dev, sizeof(*type_c_cfg), GFP_KERNEL);
>
> + if (!type_c->type_c_cfg) {
> + dev_err(dev, "Failed to allocate memory for type_c_cfg!\n");
> + ret = -ENOMEM;
> + goto err;
> + }
> +
> memcpy(type_c->type_c_cfg, type_c_cfg, sizeof(*type_c_cfg));
…
I suggest to omit an extra error message here.
By the way:
Would you become interested to add a jump target for the statement “ret = -EINVAL;”
(in two other if branches)?
Regards,
Markus