* Re: [Intel-wired-lan] [PATCH net v4] ice: Add check for kzalloc
@ 2023-01-04 7:01 Stany V, Vasanth
0 siblings, 0 replies; 4+ messages in thread
From: Stany V, Vasanth @ 2023-01-04 7:01 UTC (permalink / raw)
To: Jiasheng Jiang, jiri, leon, intel-wired-lan, Brandeburg, Jesse,
linux-kernel, edumazet, Nguyen, Anthony L, netdev, kuba, pabeni,
davem
[-- Attachment #1.1: Type: text/plain, Size: 1807 bytes --]
> -----Original Message-----
> From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org<mailto:intel-wired-lan-bounces@osuosl.org>> On Behalf Of Jiasheng Jiang
> Sent: Thursday, December 8, 2022 5:36 AM
> To: jiri@resnulli.us<mailto:jiri@resnulli.us>
> Cc: leon@kernel.org<mailto:leon@kernel.org>; intel-wired-lan@lists.osuosl.org<mailto:intel-wired-lan@lists.osuosl.org>; Jiasheng Jiang <jiasheng@iscas.ac.cn<mailto:jiasheng@iscas.ac.cn>>; Brandeburg, Jesse <jesse.brandeburg@intel.com<mailto:jesse.brandeburg@intel.com>>; linux-kernel@vger.kernel.org<mailto:linux-kernel@vger.kernel.org>; edumazet@google.com<mailto:edumazet@google.com>; Nguyen, Anthony L <anthony.l.nguyen@intel.com<mailto:anthony.l.nguyen@intel.com>>; > netdev@vger.kernel.org<mailto:netdev@vger.kernel.org>; kuba@kernel.org<mailto:kuba@kernel.org>; pabeni@redhat.com<mailto:pabeni@redhat.com>; davem@davemloft.net<mailto:davem@davemloft.net>
> Subject: [Intel-wired-lan] [PATCH net v4] ice: Add check for kzalloc
>
> Add the check for the return value of kzalloc in order to avoid NULL pointer dereference.
> Moreover, use the goto-label to share the clean code.
>
> Fixes: d6b98c8d242a ("ice: add write functionality for GNSS TTY")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn<mailto:jiasheng@iscas.ac.cn>>
> ---
> Changelog:
>
> v3 -> v4:
>
> 1. Move the check right after the kzalloc.
>
> v2 -> v3:
>
> 1. Use "while (i--)" to simplify the code.
>
> v1 -> v2:
>
> 1. Use goto-label to share the clean code.
> ---
> drivers/net/ethernet/intel/ice/ice_gnss.c | 23 ++++++++++++++---------
> 1 file changed, 14 insertions(+), 9 deletions(-)
Tested-by: Vasanth Stany < vasanth.stany.v@intel.com<mailto:vasanth.stany.v@intel.com> >
[-- Attachment #1.2: Type: text/html, Size: 5264 bytes --]
[-- Attachment #2: Type: text/plain, Size: 162 bytes --]
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan@osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Intel-wired-lan] [PATCH net v4] ice: Add check for kzalloc
2022-12-08 13:35 Jiasheng Jiang
2022-12-08 16:02 ` Jiri Pirko
@ 2023-01-05 5:52 ` G, GurucharanX
1 sibling, 0 replies; 4+ messages in thread
From: G, GurucharanX @ 2023-01-05 5:52 UTC (permalink / raw)
To: Jiasheng Jiang, jiri
Cc: leon, netdev, Brandeburg, Jesse, linux-kernel, edumazet, Nguyen,
Anthony L, kuba, intel-wired-lan, pabeni, davem
> -----Original Message-----
> From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org> On Behalf Of
> Jiasheng Jiang
> Sent: Thursday, December 8, 2022 7:06 PM
> To: jiri@resnulli.us
> Cc: leon@kernel.org; intel-wired-lan@lists.osuosl.org; Jiasheng Jiang
> <jiasheng@iscas.ac.cn>; Brandeburg, Jesse <jesse.brandeburg@intel.com>;
> linux-kernel@vger.kernel.org; edumazet@google.com; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; netdev@vger.kernel.org; kuba@kernel.org;
> pabeni@redhat.com; davem@davemloft.net
> Subject: [Intel-wired-lan] [PATCH net v4] ice: Add check for kzalloc
>
> Add the check for the return value of kzalloc in order to avoid NULL pointer
> dereference.
> Moreover, use the goto-label to share the clean code.
>
> Fixes: d6b98c8d242a ("ice: add write functionality for GNSS TTY")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
> Changelog:
>
> v3 -> v4:
>
> 1. Move the check right after the kzalloc.
>
> v2 -> v3:
>
> 1. Use "while (i--)" to simplify the code.
>
> v1 -> v2:
>
> 1. Use goto-label to share the clean code.
> ---
> drivers/net/ethernet/intel/ice/ice_gnss.c | 23 ++++++++++++++---------
> 1 file changed, 14 insertions(+), 9 deletions(-)
>
Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan@osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Intel-wired-lan] [PATCH net v4] ice: Add check for kzalloc
2022-12-08 13:35 Jiasheng Jiang
@ 2022-12-08 16:02 ` Jiri Pirko
2023-01-05 5:52 ` G, GurucharanX
1 sibling, 0 replies; 4+ messages in thread
From: Jiri Pirko @ 2022-12-08 16:02 UTC (permalink / raw)
To: Jiasheng Jiang
Cc: leon, intel-wired-lan, jesse.brandeburg, linux-kernel, edumazet,
anthony.l.nguyen, netdev, kuba, pabeni, davem
Thu, Dec 08, 2022 at 02:35:52PM CET, jiasheng@iscas.ac.cn wrote:
>Add the check for the return value of kzalloc in order to avoid
>NULL pointer dereference.
>Moreover, use the goto-label to share the clean code.
>
>Fixes: d6b98c8d242a ("ice: add write functionality for GNSS TTY")
>Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan@osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Intel-wired-lan] [PATCH net v4] ice: Add check for kzalloc
@ 2022-12-08 13:35 Jiasheng Jiang
2022-12-08 16:02 ` Jiri Pirko
2023-01-05 5:52 ` G, GurucharanX
0 siblings, 2 replies; 4+ messages in thread
From: Jiasheng Jiang @ 2022-12-08 13:35 UTC (permalink / raw)
To: jiri
Cc: leon, intel-wired-lan, Jiasheng Jiang, jesse.brandeburg,
linux-kernel, edumazet, anthony.l.nguyen, netdev, kuba, pabeni,
davem
Add the check for the return value of kzalloc in order to avoid
NULL pointer dereference.
Moreover, use the goto-label to share the clean code.
Fixes: d6b98c8d242a ("ice: add write functionality for GNSS TTY")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
Changelog:
v3 -> v4:
1. Move the check right after the kzalloc.
v2 -> v3:
1. Use "while (i--)" to simplify the code.
v1 -> v2:
1. Use goto-label to share the clean code.
---
drivers/net/ethernet/intel/ice/ice_gnss.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/drivers/net/ethernet/intel/ice/ice_gnss.c b/drivers/net/ethernet/intel/ice/ice_gnss.c
index b5a7f246d230..60b6c7125616 100644
--- a/drivers/net/ethernet/intel/ice/ice_gnss.c
+++ b/drivers/net/ethernet/intel/ice/ice_gnss.c
@@ -460,6 +460,9 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf)
for (i = 0; i < ICE_GNSS_TTY_MINOR_DEVICES; i++) {
pf->gnss_tty_port[i] = kzalloc(sizeof(*pf->gnss_tty_port[i]),
GFP_KERNEL);
+ if (!pf->gnss_tty_port[i])
+ goto err_out;
+
pf->gnss_serial[i] = NULL;
tty_port_init(pf->gnss_tty_port[i]);
@@ -469,21 +472,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;
}
for (i = 0; i < ICE_GNSS_TTY_MINOR_DEVICES; i++)
dev_info(dev, "%s%d registered\n", ttydrv_name, i);
return tty_driver;
+
+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;
}
/**
--
2.25.1
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan@osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-01-05 5:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-04 7:01 [Intel-wired-lan] [PATCH net v4] ice: Add check for kzalloc Stany V, Vasanth
-- strict thread matches above, loose matches on Subject: below --
2022-12-08 13:35 Jiasheng Jiang
2022-12-08 16:02 ` Jiri Pirko
2023-01-05 5:52 ` G, GurucharanX
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).