From: Jiri Pirko <jiri@resnulli.us>
To: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Cc: intel-wired-lan@lists.osuosl.org, jesse.brandeburg@intel.com,
linux-kernel@vger.kernel.org, edumazet@google.com,
anthony.l.nguyen@intel.com, netdev@vger.kernel.org,
kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net
Subject: Re: [Intel-wired-lan] [PATCH net] ice: Add check for kzalloc
Date: Tue, 6 Dec 2022 10:47:01 +0100 [thread overview]
Message-ID: <Y48PlUNsVKlvpRTd@nanopsycho> (raw)
In-Reply-To: <20221206030805.15934-1-jiasheng@iscas.ac.cn>
Tue, Dec 06, 2022 at 04:08:05AM CET, jiasheng@iscas.ac.cn wrote:
>As kzalloc may fail and return NULL pointer,
>it should be better to check the return value
>in order to avoid the NULL pointer dereference.
Okay, so? Be imperative to the code base, tell it what to do in your
patch description.
>
>Fixes: d6b98c8d242a ("ice: add write functionality for GNSS TTY")
>Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
>---
> drivers/net/ethernet/intel/ice/ice_gnss.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
>diff --git a/drivers/net/ethernet/intel/ice/ice_gnss.c b/drivers/net/ethernet/intel/ice/ice_gnss.c
>index b5a7f246d230..6d3d5e75726b 100644
>--- a/drivers/net/ethernet/intel/ice/ice_gnss.c
>+++ b/drivers/net/ethernet/intel/ice/ice_gnss.c
>@@ -421,7 +421,7 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf)
> const int ICE_TTYDRV_NAME_MAX = 14;
> struct tty_driver *tty_driver;
> char *ttydrv_name;
>- unsigned int i;
>+ unsigned int i, j;
> int err;
>
> tty_driver = tty_alloc_driver(ICE_GNSS_TTY_MINOR_DEVICES,
>@@ -462,6 +462,17 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf)
> GFP_KERNEL);
> pf->gnss_serial[i] = NULL;
>
>+ if (!pf->gnss_tty_port[i]) {
>+ for (j = 0; j < i; j++) {
>+ tty_port_destroy(pf->gnss_tty_port[j]);
You are destroying port which you didn't call (pf->gnss_tty_port[i])
for. Also, you are introducing a code duplication here with the error
path couple of lines below. Please convert this to goto-label error
path so the cleanup code is shared.
>+ kfree(pf->gnss_tty_port[j]);
>+ }
>+ kfree(ttydrv_name);
>+ tty_driver_kref_put(pf->ice_gnss_tty_driver);
>+
>+ return NULL;
>+ }
>+
> tty_port_init(pf->gnss_tty_port[i]);
> tty_port_link_device(pf->gnss_tty_port[i], tty_driver, i);
> }
>--
>2.25.1
>
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan@osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
WARNING: multiple messages have this Message-ID (diff)
From: Jiri Pirko <jiri@resnulli.us>
To: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Cc: jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, intel-wired-lan@lists.osuosl.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net] ice: Add check for kzalloc
Date: Tue, 6 Dec 2022 10:47:01 +0100 [thread overview]
Message-ID: <Y48PlUNsVKlvpRTd@nanopsycho> (raw)
In-Reply-To: <20221206030805.15934-1-jiasheng@iscas.ac.cn>
Tue, Dec 06, 2022 at 04:08:05AM CET, jiasheng@iscas.ac.cn wrote:
>As kzalloc may fail and return NULL pointer,
>it should be better to check the return value
>in order to avoid the NULL pointer dereference.
Okay, so? Be imperative to the code base, tell it what to do in your
patch description.
>
>Fixes: d6b98c8d242a ("ice: add write functionality for GNSS TTY")
>Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
>---
> drivers/net/ethernet/intel/ice/ice_gnss.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
>diff --git a/drivers/net/ethernet/intel/ice/ice_gnss.c b/drivers/net/ethernet/intel/ice/ice_gnss.c
>index b5a7f246d230..6d3d5e75726b 100644
>--- a/drivers/net/ethernet/intel/ice/ice_gnss.c
>+++ b/drivers/net/ethernet/intel/ice/ice_gnss.c
>@@ -421,7 +421,7 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf)
> const int ICE_TTYDRV_NAME_MAX = 14;
> struct tty_driver *tty_driver;
> char *ttydrv_name;
>- unsigned int i;
>+ unsigned int i, j;
> int err;
>
> tty_driver = tty_alloc_driver(ICE_GNSS_TTY_MINOR_DEVICES,
>@@ -462,6 +462,17 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf)
> GFP_KERNEL);
> pf->gnss_serial[i] = NULL;
>
>+ if (!pf->gnss_tty_port[i]) {
>+ for (j = 0; j < i; j++) {
>+ tty_port_destroy(pf->gnss_tty_port[j]);
You are destroying port which you didn't call (pf->gnss_tty_port[i])
for. Also, you are introducing a code duplication here with the error
path couple of lines below. Please convert this to goto-label error
path so the cleanup code is shared.
>+ kfree(pf->gnss_tty_port[j]);
>+ }
>+ kfree(ttydrv_name);
>+ tty_driver_kref_put(pf->ice_gnss_tty_driver);
>+
>+ return NULL;
>+ }
>+
> tty_port_init(pf->gnss_tty_port[i]);
> tty_port_link_device(pf->gnss_tty_port[i], tty_driver, i);
> }
>--
>2.25.1
>
next prev parent reply other threads:[~2022-12-06 9:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-06 3:08 [Intel-wired-lan] [PATCH net] ice: Add check for kzalloc Jiasheng Jiang
2022-12-06 3:08 ` Jiasheng Jiang
2022-12-06 9:47 ` Jiri Pirko [this message]
2022-12-06 9:47 ` Jiri Pirko
2022-12-06 9:51 ` [Intel-wired-lan] " Leon Romanovsky
2022-12-06 9:51 ` Leon Romanovsky
-- strict thread matches above, loose matches on Subject: below --
2022-12-07 2:20 [Intel-wired-lan] " Jiasheng Jiang
2022-12-07 13:41 ` Jiri Pirko
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=Y48PlUNsVKlvpRTd@nanopsycho \
--to=jiri@resnulli.us \
--cc=anthony.l.nguyen@intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=jesse.brandeburg@intel.com \
--cc=jiasheng@iscas.ac.cn \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.