From: Jakub Kicinski <kuba@kernel.org>
To: Tony Nguyen <anthony.l.nguyen@intel.com>
Cc: davem@davemloft.net, pabeni@redhat.com, edumazet@google.com,
Jiasheng Jiang <jiasheng@iscas.ac.cn>,
netdev@vger.kernel.org, Jiri Pirko <jiri@nvidia.com>,
Gurucharan G <gurucharanx.g@intel.com>
Subject: Re: [PATCH net 2/2] ice: Add check for kzalloc
Date: Tue, 10 Jan 2023 18:26:07 -0800 [thread overview]
Message-ID: <20230110182607.3a41ab85@kernel.org> (raw)
In-Reply-To: <20230109225358.3478060-3-anthony.l.nguyen@intel.com>
On Mon, 9 Jan 2023 14:53:58 -0800 Tony Nguyen wrote:
> @@ -470,21 +473,23 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf)
> err = tty_register_driver(tty_driver);
> if (err) {
> dev_err(dev, "Failed to register TTY driver err=%d\n", err);
> -
> - for (i = 0; i < ICE_GNSS_TTY_MINOR_DEVICES; i++) {
> - tty_port_destroy(pf->gnss_tty_port[i]);
> - kfree(pf->gnss_tty_port[i]);
> - }
> - kfree(ttydrv_name);
> - tty_driver_kref_put(pf->ice_gnss_tty_driver);
> -
> - return NULL;
> + goto err_out;
FTR I think that depending on i == ICE_GNSS_TTY_MINOR_DEVICES
here is fragile. I can merge as is, since the code is technically
correct, but what you should have done is crate a new label, say
err_unreg_all_ports, do:
goto err_unreg_all_ports;
> }
>
> for (i = 0; i < ICE_GNSS_TTY_MINOR_DEVICES; i++)
> dev_info(dev, "%s%d registered\n", ttydrv_name, i);
>
> return tty_driver;
> +
And here add:
err_unreg_all_ports:
i = ICE_GNSS_TTY_MINOR_DEVICES;
> +err_out:
> + while (i--) {
> + tty_port_destroy(pf->gnss_tty_port[i]);
> + kfree(pf->gnss_tty_port[i]);
> + }
> + kfree(ttydrv_name);
> + tty_driver_kref_put(pf->ice_gnss_tty_driver);
> +
> + return NULL;
next prev parent reply other threads:[~2023-01-11 2:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-09 22:53 [PATCH net 0/2][pull request] Intel Wired LAN Driver Updates 2023-01-09 (ice) Tony Nguyen
2023-01-09 22:53 ` [PATCH net 1/2] ice: Fix potential memory leak in ice_gnss_tty_write() Tony Nguyen
2023-01-09 22:53 ` [PATCH net 2/2] ice: Add check for kzalloc Tony Nguyen
2023-01-10 10:56 ` Leon Romanovsky
2023-01-11 2:26 ` Jakub Kicinski [this message]
2023-01-11 19:31 ` Tony Nguyen
2023-01-11 20:01 ` Jakub Kicinski
2023-01-11 2:30 ` [PATCH net 0/2][pull request] Intel Wired LAN Driver Updates 2023-01-09 (ice) patchwork-bot+netdevbpf
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=20230110182607.3a41ab85@kernel.org \
--to=kuba@kernel.org \
--cc=anthony.l.nguyen@intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gurucharanx.g@intel.com \
--cc=jiasheng@iscas.ac.cn \
--cc=jiri@nvidia.com \
--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.