[PATCH 3/9] gpib: cec: Unify *allocate_private

Dominik Karol Piątkowski posted 9 patches 3 weeks, 6 days ago
There is a newer version of this series
[PATCH 3/9] gpib: cec: Unify *allocate_private
Posted by Dominik Karol Piątkowski 3 weeks, 6 days ago
Return values for *allocate_private functions as well as calling code in
gpib driver are all over the place. Unify them by returning -errno if
something fails, zero otherwise. Use the returned value as early return
value in case of error.

Signed-off-by: Dominik Karol Piątkowski <dominik.karol.piatkowski@protonmail.com>
---
 drivers/gpib/cec/cec_gpib.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/gpib/cec/cec_gpib.c b/drivers/gpib/cec/cec_gpib.c
index dbf9b95baabc..6d04becd1058 100644
--- a/drivers/gpib/cec/cec_gpib.c
+++ b/drivers/gpib/cec/cec_gpib.c
@@ -222,7 +222,7 @@ static int cec_allocate_private(struct gpib_board *board)
 
 	board->private_data = kmalloc(sizeof(struct cec_priv), GFP_KERNEL);
 	if (!board->private_data)
-		return -1;
+		return -ENOMEM;
 	priv = board->private_data;
 	memset(priv, 0, sizeof(struct cec_priv));
 	init_nec7210_private(&priv->nec7210_priv);
@@ -239,11 +239,13 @@ static int cec_generic_attach(struct gpib_board *board)
 {
 	struct cec_priv *cec_priv;
 	struct nec7210_priv *nec_priv;
+	int retval;
 
 	board->status = 0;
 
-	if (cec_allocate_private(board))
-		return -ENOMEM;
+	retval = cec_allocate_private(board);
+	if (retval < 0)
+		return retval;
 	cec_priv = board->private_data;
 	nec_priv = &cec_priv->nec7210_priv;
 	nec_priv->read_byte = nec7210_ioport_read_byte;
-- 
2.43.0
Re: [PATCH 3/9] gpib: cec: Unify *allocate_private
Posted by Dave Penkler 3 weeks, 4 days ago
On Tue, Jan 13, 2026 at 07:08:56PM +0000, Dominik Karol Pi??tkowski wrote:
> Return values for *allocate_private functions as well as calling code in
> gpib driver are all over the place. Unify them by returning -errno if
> something fails, zero otherwise. Use the returned value as early return
> value in case of error.
> 
> Signed-off-by: Dominik Karol Pi??tkowski <dominik.karol.piatkowski@protonmail.com>
> ---
>  drivers/gpib/cec/cec_gpib.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpib/cec/cec_gpib.c b/drivers/gpib/cec/cec_gpib.c
> index dbf9b95baabc..6d04becd1058 100644
> --- a/drivers/gpib/cec/cec_gpib.c
> +++ b/drivers/gpib/cec/cec_gpib.c
> @@ -222,7 +222,7 @@ static int cec_allocate_private(struct gpib_board *board)
>  
>  	board->private_data = kmalloc(sizeof(struct cec_priv), GFP_KERNEL);

Maybe you could change all the remaining kmalloc/memset pairs to kzalloc at the same time ?

>  	if (!board->private_data)
> -		return -1;
> +		return -ENOMEM;
>  	priv = board->private_data;
>  	memset(priv, 0, sizeof(struct cec_priv));
>  	init_nec7210_private(&priv->nec7210_priv);
> @@ -239,11 +239,13 @@ static int cec_generic_attach(struct gpib_board *board)
>  {
>  	struct cec_priv *cec_priv;
>  	struct nec7210_priv *nec_priv;
> +	int retval;
>  
>  	board->status = 0;
>  
> -	if (cec_allocate_private(board))
> -		return -ENOMEM;
> +	retval = cec_allocate_private(board);
> +	if (retval < 0)
> +		return retval;
>  	cec_priv = board->private_data;
>  	nec_priv = &cec_priv->nec7210_priv;
>  	nec_priv->read_byte = nec7210_ioport_read_byte;
> -- 
> 2.43.0
> 
>
Re: [PATCH 3/9] gpib: cec: Unify *allocate_private
Posted by Greg Kroah-Hartman 3 weeks, 3 days ago
On Thu, Jan 15, 2026 at 05:29:44PM +0100, Dave Penkler wrote:
> On Tue, Jan 13, 2026 at 07:08:56PM +0000, Dominik Karol Pi??tkowski wrote:
> > Return values for *allocate_private functions as well as calling code in
> > gpib driver are all over the place. Unify them by returning -errno if
> > something fails, zero otherwise. Use the returned value as early return
> > value in case of error.
> > 
> > Signed-off-by: Dominik Karol Pi??tkowski <dominik.karol.piatkowski@protonmail.com>
> > ---
> >  drivers/gpib/cec/cec_gpib.c | 8 +++++---
> >  1 file changed, 5 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/gpib/cec/cec_gpib.c b/drivers/gpib/cec/cec_gpib.c
> > index dbf9b95baabc..6d04becd1058 100644
> > --- a/drivers/gpib/cec/cec_gpib.c
> > +++ b/drivers/gpib/cec/cec_gpib.c
> > @@ -222,7 +222,7 @@ static int cec_allocate_private(struct gpib_board *board)
> >  
> >  	board->private_data = kmalloc(sizeof(struct cec_priv), GFP_KERNEL);
> 
> Maybe you could change all the remaining kmalloc/memset pairs to kzalloc at the same time ?

That's a different logical change, and should be in a different patch,
just to ensure that it is easier to review and roll back if something
went wrong.

thanks,

greg k-h
Re: [PATCH 3/9] gpib: cec: Unify *allocate_private
Posted by Dominik Karol Piątkowski 3 weeks, 4 days ago
Hi Dave,

On Thursday, January 15th, 2026 at 17:29, Dave Penkler <dpenkler@gmail.com> wrote:

> 
> 
> On Tue, Jan 13, 2026 at 07:08:56PM +0000, Dominik Karol Pi??tkowski wrote:
> 
> > Return values for *allocate_private functions as well as calling code in
> > gpib driver are all over the place. Unify them by returning -errno if
> > something fails, zero otherwise. Use the returned value as early return
> > value in case of error.
> > 
> > Signed-off-by: Dominik Karol Pi??tkowski dominik.karol.piatkowski@protonmail.com
> > ---
> > drivers/gpib/cec/cec_gpib.c | 8 +++++---
> > 1 file changed, 5 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/gpib/cec/cec_gpib.c b/drivers/gpib/cec/cec_gpib.c
> > index dbf9b95baabc..6d04becd1058 100644
> > --- a/drivers/gpib/cec/cec_gpib.c
> > +++ b/drivers/gpib/cec/cec_gpib.c
> > @@ -222,7 +222,7 @@ static int cec_allocate_private(struct gpib_board *board)
> > 
> > board->private_data = kmalloc(sizeof(struct cec_priv), GFP_KERNEL);
> 
> 
> Maybe you could change all the remaining kmalloc/memset pairs to kzalloc at the same time ?

Sure, thanks for the suggestion!

Dominik Karol

> 
> > if (!board->private_data)
> > - return -1;
> > + return -ENOMEM;
> > priv = board->private_data;
> > memset(priv, 0, sizeof(struct cec_priv));
> > init_nec7210_private(&priv->nec7210_priv);
> > @@ -239,11 +239,13 @@ static int cec_generic_attach(struct gpib_board *board)
> > {
> > struct cec_priv *cec_priv;
> > struct nec7210_priv *nec_priv;
> > + int retval;
> > 
> > board->status = 0;
> > 
> > - if (cec_allocate_private(board))
> > - return -ENOMEM;
> > + retval = cec_allocate_private(board);
> > + if (retval < 0)
> > + return retval;
> > cec_priv = board->private_data;
> > nec_priv = &cec_priv->nec7210_priv;
> > nec_priv->read_byte = nec7210_ioport_read_byte;
> > --
> > 2.43.0