* [PATCH] Fix possible NULL Pointer Dereference in 'extcon_rtk_type_c_probe'
@ 2024-09-29 22:38 Gax-c
2024-09-30 15:25 ` Markus Elfring
2024-10-01 19:48 ` Krzysztof Kozlowski
0 siblings, 2 replies; 3+ messages in thread
From: Gax-c @ 2024-09-29 22:38 UTC (permalink / raw)
To: myungjoo.ham, cw00.choi, stanley_chang
Cc: linux-kernel, Gax-c, Zijie Zhao, Chenyuan Yang
A 'devm_kzalloc' in 'extcon_rtk_type_c_probe' could possibly return null pointer.
Add a null check for the returned pointer.
Fixes: 8a590d7371f0 ("extcon: add Realtek DHC RTD SoC Type-C driver")
Signed-off-by: Zichen Xie <zichenxie0106@gmail.com>
Reported-by: Zichen Xie <zichenxie0106@gmail.com>
Reported-by: Zijie Zhao <zzjas98@gmail.com>
Reported-by: Chenyuan Yang <chenyuan0y@gmail.com>
---
drivers/extcon/extcon-rtk-type-c.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/extcon/extcon-rtk-type-c.c b/drivers/extcon/extcon-rtk-type-c.c
index a592bab77538..9a0824fc7cbe 100644
--- a/drivers/extcon/extcon-rtk-type-c.c
+++ 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));
if (setup_type_c_parameter(type_c)) {
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] Fix possible NULL Pointer Dereference in 'extcon_rtk_type_c_probe'
2024-09-29 22:38 [PATCH] Fix possible NULL Pointer Dereference in 'extcon_rtk_type_c_probe' Gax-c
@ 2024-09-30 15:25 ` Markus Elfring
2024-10-01 19:48 ` Krzysztof Kozlowski
1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2024-09-30 15:25 UTC (permalink / raw)
To: Zichen Xie, kernel-janitors, Chanwoo Choi, MyungJoo Ham, Stanley Chang
Cc: LKML, Zijie Zhao, Chenyuan Yang
> 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@gmail.com>
> Reported-by: Zichen Xie <zichenxie0106@gmail.com>
…
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
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] Fix possible NULL Pointer Dereference in 'extcon_rtk_type_c_probe'
2024-09-29 22:38 [PATCH] Fix possible NULL Pointer Dereference in 'extcon_rtk_type_c_probe' Gax-c
2024-09-30 15:25 ` Markus Elfring
@ 2024-10-01 19:48 ` Krzysztof Kozlowski
1 sibling, 0 replies; 3+ messages in thread
From: Krzysztof Kozlowski @ 2024-10-01 19:48 UTC (permalink / raw)
To: Gax-c, myungjoo.ham, cw00.choi, stanley_chang
Cc: linux-kernel, Zijie Zhao, Chenyuan Yang
On 30/09/2024 00:38, Gax-c wrote:
> A 'devm_kzalloc' in 'extcon_rtk_type_c_probe' could possibly return null pointer.
> Add a null check for the returned pointer.
>
> Fixes: 8a590d7371f0 ("extcon: add Realtek DHC RTD SoC Type-C driver")
> Signed-off-by: Zichen Xie <zichenxie0106@gmail.com>
> Reported-by: Zichen Xie <zichenxie0106@gmail.com>
> Reported-by: Zijie Zhao <zzjas98@gmail.com>
> Reported-by: Chenyuan Yang <chenyuan0y@gmail.com>
All previous comments apply.
> ---
> drivers/extcon/extcon-rtk-type-c.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/extcon/extcon-rtk-type-c.c b/drivers/extcon/extcon-rtk-type-c.c
> index a592bab77538..9a0824fc7cbe 100644
> --- a/drivers/extcon/extcon-rtk-type-c.c
> +++ 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);
>
Same as in other patches - drop blank line.
> + if (!type_c->type_c_cfg) {
> + dev_err(dev, "Failed to allocate memory for type_c_cfg!\n");
No, drop.
> + ret = -ENOMEM;
> + goto err;
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-01 19:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-29 22:38 [PATCH] Fix possible NULL Pointer Dereference in 'extcon_rtk_type_c_probe' Gax-c
2024-09-30 15:25 ` Markus Elfring
2024-10-01 19:48 ` Krzysztof Kozlowski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®