From: Mukesh Ojha <mojha@codeaurora.org>
To: Aditya Pakki <pakki001@umn.edu>, pakki001@um.edu
Cc: kjlu@umn.edu, Andreas Noever <andreas.noever@gmail.com>,
Michael Jamet <michael.jamet@intel.com>,
Mika Westerberg <mika.westerberg@linux.intel.com>,
Yehezkel Bernat <YehezkelShB@gmail.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] thunderbolt: Fix to check for kmemdup failure
Date: Wed, 20 Mar 2019 17:39:35 +0530 [thread overview]
Message-ID: <3984668e-9ac6-1e47-01fc-dfab8cd77cae@codeaurora.org> (raw)
In-Reply-To: <20190318224417.7500-1-pakki001@umn.edu>
On 3/19/2019 4:14 AM, Aditya Pakki wrote:
> Memory allocated via kmemdup might fail and return a NULL pointer.
> This patch adds a check on the return value of kmemdup and passes the
> error upstream.
>
> Signed-off-by: Aditya Pakki <pakki001@umn.edu>
> ---
> drivers/thunderbolt/switch.c | 15 +++++++++++----
> 1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c
> index cd96994dc094..c05d77073ee7 100644
> --- a/drivers/thunderbolt/switch.c
> +++ b/drivers/thunderbolt/switch.c
> @@ -1294,13 +1294,13 @@ int tb_switch_configure(struct tb_switch *sw)
> return tb_plug_events_active(sw, true);
> }
>
> -static void tb_switch_set_uuid(struct tb_switch *sw)
> +static int tb_switch_set_uuid(struct tb_switch *sw)
> {
> u32 uuid[4];
> int cap;
>
> if (sw->uuid)
> - return;
> + return 0;
>
> /*
> * The newer controllers include fused UUID as part of link
> @@ -1323,6 +1323,9 @@ static void tb_switch_set_uuid(struct tb_switch *sw)
> }
>
> sw->uuid = kmemdup(uuid, sizeof(uuid), GFP_KERNEL);
> + if (!sw->uuid)
> + return -ENOMEM;
> + return 0;
> }
>
Change looks good to me.
Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>
but, we should add check for `tb_sw_read ` this as well.
Cheers,
Mukesh
> static int tb_switch_add_dma_port(struct tb_switch *sw)
> @@ -1372,7 +1375,9 @@ static int tb_switch_add_dma_port(struct tb_switch *sw)
>
> if (status) {
> tb_sw_info(sw, "switch flash authentication failed\n");
> - tb_switch_set_uuid(sw);
> + ret = tb_switch_set_uuid(sw);
> + if (ret)
> + return ret;
> nvm_set_auth_status(sw, status);
>
>
> @@ -1Reviewed-by: Andy Shevchenko<andriy.shevchenko@linux.intel.com>422,7 +1427,9 @@ int tb_switch_add(struct tb_switch *sw)
> }
> tb_sw_dbg(sw, "uid: %#llx\n", sw->uid);
>
> - tb_switch_set_uuid(sw);
> + ret = tb_switch_set_uuid(sw);
> + if (ret)
> + return ret;
>
> for (i = 0; i <= sw->config.max_port_number; i++) {
> if (sw->ports[i].disabled) {
prev parent reply other threads:[~2019-03-20 12:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-18 22:44 [PATCH] thunderbolt: Fix to check for kmemdup failure Aditya Pakki
2019-03-20 10:45 ` Mika Westerberg
2019-03-20 12:09 ` Mukesh Ojha [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=3984668e-9ac6-1e47-01fc-dfab8cd77cae@codeaurora.org \
--to=mojha@codeaurora.org \
--cc=YehezkelShB@gmail.com \
--cc=andreas.noever@gmail.com \
--cc=kjlu@umn.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=michael.jamet@intel.com \
--cc=mika.westerberg@linux.intel.com \
--cc=pakki001@um.edu \
--cc=pakki001@umn.edu \
/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