From: Viken Dadhaniya <quic_vdadhani@quicinc.com>
To: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
<andersson@kernel.org>, <konrad.dybcio@linaro.org>,
<linux-arm-msm@vger.kernel.org>, <alsa-devel@alsa-project.org>,
<linux-kernel@vger.kernel.org>
Cc: <quic_msavaliy@quicinc.com>, <quic_vtanuku@quicinc.com>,
<quic_anupkulk@quicinc.com>, <quic_cchiluve@quicinc.com>
Subject: Re: [PATCH v1 RESEND] slimbus: stream: Add null pointer check for client functions
Date: Wed, 17 Apr 2024 15:08:37 +0530 [thread overview]
Message-ID: <aef94318-4c32-4b9d-867f-25f366d425bd@quicinc.com> (raw)
In-Reply-To: <d2a4a91d-1b8a-4136-af30-50eb693423df@linaro.org>
On 4/11/2024 3:19 PM, Srinivas Kandagatla wrote:
> Thanks Viken for the patch,
>
> On 27/03/2024 08:32, Viken Dadhaniya wrote:
>> There is a possible scenario where client driver is calling
>> slimbus stream APIs in incorrect sequence and it might lead to
>> invalid null access of the stream pointer in slimbus
>> enable/disable/prepare/unprepare/free function.
>>
>> Fix this by checking validity of the stream before accessing in
>> all function API’s exposed to client.
>>
>> Signed-off-by: Viken Dadhaniya <quic_vdadhani@quicinc.com>
>> ---
>> drivers/slimbus/stream.c | 37 +++++++++++++++++++++++++++++++++----
>> 1 file changed, 33 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/slimbus/stream.c b/drivers/slimbus/stream.c
>> index 1d6b38657917..c5a436fd0952 100644
>> --- a/drivers/slimbus/stream.c
>> +++ b/drivers/slimbus/stream.c
>> @@ -202,10 +202,16 @@ static int slim_get_prate_code(int rate)
>> int slim_stream_prepare(struct slim_stream_runtime *rt,
>> struct slim_stream_config *cfg)
>> {
>> - struct slim_controller *ctrl = rt->dev->ctrl;
>> + struct slim_controller *ctrl;
>> struct slim_port *port;
>> int num_ports, i, port_id, prrate;
>> + if (!rt || !cfg) {
>> + pr_err("%s: Stream or cfg is NULL, Check from client side\n",
>> __func__);
>
> Please use dev_err where possible
>
>
> --srini
For error scenario, we don't have valid dev to be used in dev_err
argument. this log will help for debug.
Please let us know if any concern with pr_err.
>> + return -EINVAL;
>> + }
>> +
>> + ctrl = rt->dev->ctrl;
>> if (rt->ports) {
>> dev_err(&rt->dev->dev, "Stream already Prepared\n");
>> return -EINVAL;
>> @@ -358,9 +364,15 @@ int slim_stream_enable(struct slim_stream_runtime
>> *stream)
>> {
>> DEFINE_SLIM_BCAST_TXN(txn, SLIM_MSG_MC_BEGIN_RECONFIGURATION,
>> 3, SLIM_LA_MANAGER, NULL);
>> - struct slim_controller *ctrl = stream->dev->ctrl;
>> + struct slim_controller *ctrl;
>> int ret, i;
>> + if (!stream) {
>> + pr_err("%s: Stream is NULL, Check from client side\n",
>> __func__);
>> + return -EINVAL;
>> + }
>> +
>> + ctrl = stream->dev->ctrl;
>> if (ctrl->enable_stream) {
>> ret = ctrl->enable_stream(stream);
>> if (ret)
>> @@ -411,12 +423,18 @@ int slim_stream_disable(struct
>> slim_stream_runtime *stream)
>> {
>> DEFINE_SLIM_BCAST_TXN(txn, SLIM_MSG_MC_BEGIN_RECONFIGURATION,
>> 3, SLIM_LA_MANAGER, NULL);
>> - struct slim_controller *ctrl = stream->dev->ctrl;
>> + struct slim_controller *ctrl;
>> int ret, i;
>> + if (!stream) {
>> + pr_err("%s: Stream is NULL, Check from client side\n",
>> __func__);
>> + return -EINVAL;
>> + }
>> +
>> if (!stream->ports || !stream->num_ports)
>> return -EINVAL;
>> + ctrl = stream->dev->ctrl;
>> if (ctrl->disable_stream)
>> ctrl->disable_stream(stream);
>> @@ -448,6 +466,11 @@ int slim_stream_unprepare(struct
>> slim_stream_runtime *stream)
>> {
>> int i;
>> + if (!stream) {
>> + pr_err("%s: Stream is NULL, Check from client side\n",
>> __func__);
>> + return -EINVAL;
>> + }
>> +
>> if (!stream->ports || !stream->num_ports)
>> return -EINVAL;
>> @@ -476,8 +499,14 @@ EXPORT_SYMBOL_GPL(slim_stream_unprepare);
>> */
>> int slim_stream_free(struct slim_stream_runtime *stream)
>> {
>> - struct slim_device *sdev = stream->dev;
>> + struct slim_device *sdev;
>> +
>> + if (!stream) {
>> + pr_err("%s: Stream is NULL, Check from client side\n",
>> __func__);
>> + return -EINVAL;
>> + }
>> + sdev = stream->dev;
>> spin_lock(&sdev->stream_list_lock);
>> list_del(&stream->node);
>> spin_unlock(&sdev->stream_list_lock);
next prev parent reply other threads:[~2024-04-17 9:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-27 8:32 Viken Dadhaniya
2024-04-11 9:49 ` Srinivas Kandagatla
2024-04-17 9:38 ` Viken Dadhaniya [this message]
2024-04-11 15:56 ` Bjorn Andersson
2024-04-17 9:42 ` Viken Dadhaniya
2024-04-17 21:39 ` Bjorn Andersson
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=aef94318-4c32-4b9d-867f-25f366d425bd@quicinc.com \
--to=quic_vdadhani@quicinc.com \
--cc=alsa-devel@alsa-project.org \
--cc=andersson@kernel.org \
--cc=konrad.dybcio@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=quic_anupkulk@quicinc.com \
--cc=quic_cchiluve@quicinc.com \
--cc=quic_msavaliy@quicinc.com \
--cc=quic_vtanuku@quicinc.com \
--cc=srinivas.kandagatla@linaro.org \
/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
all inboxes | Powered by JetHome®