From: Manivannan Sadhasivam <mani@kernel.org>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: mhi@lists.linux.dev
Subject: Re: [bug report] bus: mhi: ep: Do not allocate event ring element on stack
Date: Wed, 25 Oct 2023 13:28:14 +0530 [thread overview]
Message-ID: <20231025075814.GE3648@thinkpad> (raw)
In-Reply-To: <e7d05eeb-2b28-477d-be3f-7f6e9ad7aec5@moroto.mountain>
On Fri, Oct 20, 2023 at 04:54:33PM +0300, Dan Carpenter wrote:
> Hello Manivannan Sadhasivam,
>
> The patch b910ee376ab3: "bus: mhi: ep: Do not allocate event ring
> element on stack" from Sep 1, 2023 (linux-next), leads to the
> following Smatch static checker warning:
>
> drivers/bus/mhi/ep/main.c:106 mhi_ep_send_ee_event() error: potential null dereference 'event'. (kzalloc returns null)
> drivers/bus/mhi/ep/main.c:121 mhi_ep_send_cmd_comp_event() error: potential null dereference 'event'. (kzalloc returns null)
> drivers/bus/mhi/ep/main.c:77 mhi_ep_send_completion_event() error: potential null dereference 'event'. (kzalloc returns null)
> drivers/bus/mhi/ep/main.c:92 mhi_ep_send_state_change_event() error: potential null dereference 'event'. (kzalloc returns null)
>
> drivers/bus/mhi/ep/main.c
> 101 int mhi_ep_send_ee_event(struct mhi_ep_cntrl *mhi_cntrl, enum mhi_ee_type exec_env)
> 102 {
> 103 struct mhi_ring_element *event = kzalloc(sizeof(struct mhi_ring_element), GFP_KERNEL);
>
> No checks for NULL. Some people have a rule that functions which can
> fail should not be in the declaration block. From a static analysis
> perspective code in the declaration block is buggier than code in the
> code area.
>
Thanks Dan for the report. Yes, it is indeed a bad idea to have the allocation
inside declaration. I will move it outside and add the error check.
- Mani
> 104 int ret;
> 105
> --> 106 event->dword[0] = MHI_EE_EV_DWORD0(exec_env);
> 107 event->dword[1] = MHI_SC_EV_DWORD1(MHI_PKT_TYPE_EE_EVENT);
> 108
> 109 ret = mhi_ep_send_event(mhi_cntrl, 0, event, 0);
> 110 kfree(event);
> 111
> 112 return ret;
> 113 }
>
> regards,
> dan carpenter
--
மணிவண்ணன் சதாசிவம்
prev parent reply other threads:[~2023-10-25 7:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-20 13:54 [bug report] bus: mhi: ep: Do not allocate event ring element on stack Dan Carpenter
2023-10-25 7:58 ` Manivannan Sadhasivam [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231025075814.GE3648@thinkpad \
--to=mani@kernel.org \
--cc=dan.carpenter@linaro.org \
--cc=mhi@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox