* [PATCH v2] staging: gpib: Fix error handling paths in cb_gpib_probe()
@ 2025-07-05 9:52 Christophe JAILLET
2025-07-05 14:17 ` Thomas Richard
0 siblings, 1 reply; 3+ messages in thread
From: Christophe JAILLET @ 2025-07-05 9:52 UTC (permalink / raw)
To: thomas.richard, Dave Penkler, Greg Kroah-Hartman
Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-staging
If cb_gpib_config() fails, 'info' needs to be freed, as already done in the
remove function.
While at it, remove a pointless comment related to gpib_attach().
Fixes: e9dc69956d4d ("staging: gpib: Add Computer Boards GPIB driver")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Changes in v2:
- Fix the Fixes tag [Thomas Richard]
- Synch with latest -next
- no compile tested. I think, thanks to commit 79d2e1919a27
("staging: gpib: fix Makefiles")
v1: https://lore.kernel.org/all/459c267de8c9bf48fcb555364930ae7e3cdc798b.1729940596.git.christophe.jaillet@wanadoo.fr/
Compile tested only.
---
drivers/staging/gpib/cb7210/cb7210.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/gpib/cb7210/cb7210.c b/drivers/staging/gpib/cb7210/cb7210.c
index 298ed306189d..3e2397898a9b 100644
--- a/drivers/staging/gpib/cb7210/cb7210.c
+++ b/drivers/staging/gpib/cb7210/cb7210.c
@@ -1184,8 +1184,7 @@ struct local_info {
static int cb_gpib_probe(struct pcmcia_device *link)
{
struct local_info *info;
-
-// int ret, i;
+ int ret;
/* Allocate space for private device-specific data */
info = kzalloc(sizeof(*info), GFP_KERNEL);
@@ -1211,8 +1210,16 @@ static int cb_gpib_probe(struct pcmcia_device *link)
/* Register with Card Services */
curr_dev = link;
- return cb_gpib_config(link);
-} /* gpib_attach */
+ ret = cb_gpib_config(link);
+ if (ret)
+ goto free_info;
+
+ return 0;
+
+free_info:
+ kfree(info);
+ return ret;
+}
/*
* This deletes a driver "instance". The device is de-registered
--
2.50.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] staging: gpib: Fix error handling paths in cb_gpib_probe()
2025-07-05 9:52 [PATCH v2] staging: gpib: Fix error handling paths in cb_gpib_probe() Christophe JAILLET
@ 2025-07-05 14:17 ` Thomas Richard
2025-07-09 11:04 ` Greg Kroah-Hartman
0 siblings, 1 reply; 3+ messages in thread
From: Thomas Richard @ 2025-07-05 14:17 UTC (permalink / raw)
To: Christophe JAILLET, Dave Penkler, Greg Kroah-Hartman
Cc: linux-kernel, kernel-janitors, linux-staging
Hi Christophe,
On 7/5/25 11:52 AM, Christophe JAILLET wrote:
> If cb_gpib_config() fails, 'info' needs to be freed, as already done in the
> remove function.
>
> While at it, remove a pointless comment related to gpib_attach().
>
> Fixes: e9dc69956d4d ("staging: gpib: Add Computer Boards GPIB driver")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Changes in v2:
> - Fix the Fixes tag [Thomas Richard]
> - Synch with latest -next
> - no compile tested. I think, thanks to commit 79d2e1919a27
> ("staging: gpib: fix Makefiles")
>
> v1: https://lore.kernel.org/all/459c267de8c9bf48fcb555364930ae7e3cdc798b.1729940596.git.christophe.jaillet@wanadoo.fr/
>
> Compile tested only.
> ---
> drivers/staging/gpib/cb7210/cb7210.c | 15 +++++++++++----
> 1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/staging/gpib/cb7210/cb7210.c b/drivers/staging/gpib/cb7210/cb7210.c
> index 298ed306189d..3e2397898a9b 100644
> --- a/drivers/staging/gpib/cb7210/cb7210.c
> +++ b/drivers/staging/gpib/cb7210/cb7210.c
> @@ -1184,8 +1184,7 @@ struct local_info {
> static int cb_gpib_probe(struct pcmcia_device *link)
> {
> struct local_info *info;
> -
> -// int ret, i;
> + int ret;
>
> /* Allocate space for private device-specific data */
> info = kzalloc(sizeof(*info), GFP_KERNEL);
You should use devm_kzalloc(). The memory will be automatically freed by
the core. So no need to call kfree() in case of error during the probe.
And you can remove the kfree() in cb_gpib_remove().
Regards,
Thomas
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] staging: gpib: Fix error handling paths in cb_gpib_probe()
2025-07-05 14:17 ` Thomas Richard
@ 2025-07-09 11:04 ` Greg Kroah-Hartman
0 siblings, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2025-07-09 11:04 UTC (permalink / raw)
To: Thomas Richard
Cc: Christophe JAILLET, Dave Penkler, linux-kernel, kernel-janitors,
linux-staging
On Sat, Jul 05, 2025 at 04:17:35PM +0200, Thomas Richard wrote:
> Hi Christophe,
>
> On 7/5/25 11:52 AM, Christophe JAILLET wrote:
> > If cb_gpib_config() fails, 'info' needs to be freed, as already done in the
> > remove function.
> >
> > While at it, remove a pointless comment related to gpib_attach().
> >
> > Fixes: e9dc69956d4d ("staging: gpib: Add Computer Boards GPIB driver")
> > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> > ---
> > Changes in v2:
> > - Fix the Fixes tag [Thomas Richard]
> > - Synch with latest -next
> > - no compile tested. I think, thanks to commit 79d2e1919a27
> > ("staging: gpib: fix Makefiles")
> >
> > v1: https://lore.kernel.org/all/459c267de8c9bf48fcb555364930ae7e3cdc798b.1729940596.git.christophe.jaillet@wanadoo.fr/
> >
> > Compile tested only.
> > ---
> > drivers/staging/gpib/cb7210/cb7210.c | 15 +++++++++++----
> > 1 file changed, 11 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/staging/gpib/cb7210/cb7210.c b/drivers/staging/gpib/cb7210/cb7210.c
> > index 298ed306189d..3e2397898a9b 100644
> > --- a/drivers/staging/gpib/cb7210/cb7210.c
> > +++ b/drivers/staging/gpib/cb7210/cb7210.c
> > @@ -1184,8 +1184,7 @@ struct local_info {
> > static int cb_gpib_probe(struct pcmcia_device *link)
> > {
> > struct local_info *info;
> > -
> > -// int ret, i;
> > + int ret;
> >
> > /* Allocate space for private device-specific data */
> > info = kzalloc(sizeof(*info), GFP_KERNEL);
>
> You should use devm_kzalloc(). The memory will be automatically freed by
> the core. So no need to call kfree() in case of error during the probe.
> And you can remove the kfree() in cb_gpib_remove().
Some people, myself include, hate the devm_*() apis, so no need to force
them on anyone please :)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-09 11:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-05 9:52 [PATCH v2] staging: gpib: Fix error handling paths in cb_gpib_probe() Christophe JAILLET
2025-07-05 14:17 ` Thomas Richard
2025-07-09 11:04 ` Greg Kroah-Hartman
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).