From: Aishwarya Pant <aishpant@gmail.com>
To: Julia Lawall <julia.lawall@lip6.fr>
Cc: outreachy-kernel@googlegroups.com
Subject: Re: [Outreachy kernel] [PATCH v5 2/7] staging: bcm2835-audio: replace null with error pointer value
Date: Fri, 10 Mar 2017 00:04:32 +0530 [thread overview]
Message-ID: <20170309183432.GA15683@aishwarya> (raw)
In-Reply-To: <alpine.DEB.2.20.1703091418370.3186@hadrien>
On Thu, Mar 09, 2017 at 02:24:08PM +0100, Julia Lawall wrote:
>
>
> On Thu, 9 Mar 2017, Aishwarya Pant wrote:
>
> > This patch replaces NULL values returned by vc_vchi_audio_init(...) with
> > error pointer values:
> > - Return ERR_PTR(-EINVAL) when too many instances of audio
> > service are initialised
> > - Return ERR_PTR(-ENOMEM) when kzalloc fails
> > - RETURN ERR_PTR(-EPERM) when vchi connections fail to open
> >
> > Similarly, a NULL check where vc_vchi_audio_init(...) is called is
> > replaced by IS_ERR(..)
> >
> > Signed-off-by: Aishwarya Pant <aishpant@gmail.com>
> > ---
> > drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c | 8 ++++----
> > 1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
> > index 005e287..d2686b4 100644
> > --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
> > +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
> > @@ -287,12 +287,12 @@ vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance,
> > LOG_ERR("%s: unsupported number of connections %u (max=%u)\n",
> > __func__, num_connections, VCHI_MAX_NUM_CONNECTIONS);
> >
> > - return NULL;
> > + return ERR_PTR(-EINVAL);
> > }
> > /* Allocate memory for this instance */
> > instance = kzalloc(sizeof(*instance), GFP_KERNEL);
> > if (!instance)
> > - return NULL;
> > + return ERR_PTR(-ENOMEM);
> >
> > instance->num_connections = num_connections;
> >
> > @@ -341,7 +341,7 @@ vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance,
> > kfree(instance);
> > LOG_ERR("%s: error\n", __func__);
> >
> > - return NULL;
> > + return ERR_PTR(-EPERM);
>
> I find it a bit odd to have -EPERM hard coded at the end of the function.
> If the function becomes more complicated, this code could end up being
> shared. In that case, different exits would have different codes. Also,
> ultimately the code should come from the result of vchi_service_open,
> although that is not suitable now.
>
> How about adding status = -EPERM just before the goto, and the putting
> return ERR_PTR(status) at the end of the function?
Yes that sounds fair.
>
> By the way, I found that having all the LOG_DBG lines made the code really
> hard to follow. Maybe it could be possible to just remove them.
>
The LOG_DBG / LOG_ERR messages here are a wrapper of pr_err / pr_dbg
appended with the current function names and line numbers. So I am
taking a guess they are useful as long as the driver is in staging.
> Another suggestion on this particular function is to do something about
> this declaration:
>
> SERVICE_CREATION_T params = {
> VCHI_VERSION_EX(VC_AUDIOSERV_VER, VC_AUDIOSERV_MIN_VER),
> VC_AUDIO_SERVER_NAME, // 4cc service code
> vchi_connections[i], // passed in fn pointers
> 0, // rx fifo size (unused)
> 0, // tx fifo size (unused)
> audio_vchi_callback, // service callback
> instance, // service callback parameter
> 1, //TODO: remove VCOS_FALSE, // unaligned bulk receives
> 1, //TODO: remove VCOS_FALSE, // unaligned bulk transmits
> 0 // want crc check on bulk transfers
> };
>
> The typedef needs to go, the fields should be initialied using their names
> (.x = e) and the comments should be dropped.
>
All-right I'll give this a go. The vchi_services driver is sprinkled
with typedefs.
> julia
>
> > }
> >
> > static int vc_vchi_audio_deinit(struct bcm2835_audio_instance *instance)
> > @@ -432,7 +432,7 @@ static int bcm2835_audio_open_connection(struct bcm2835_alsa_stream *alsa_stream
> > /* Initialize an instance of the audio service */
> > instance = vc_vchi_audio_init(vchi_instance, &vchi_connection, 1);
> >
> > - if (!instance) {
> > + if (IS_ERR(instance)) {
> > LOG_ERR("%s: failed to initialize audio service\n", __func__);
> >
> > ret = -EPERM;
> > --
> > 2.7.4
> >
> > --
> > You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com.
> > To post to this group, send email to outreachy-kernel@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/cc9cc8c7a3576a9d556815fd9f57ca58338abb01.1489055580.git.aishpant%40gmail.com.
> > For more options, visit https://groups.google.com/d/optout.
> >
next prev parent reply other threads:[~2017-03-09 18:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-09 10:37 [PATCH v5 0/7] staging: bcm2835-audio: clean-up coding style issues Aishwarya Pant
2017-03-09 10:37 ` [PATCH v5 1/7] staging: bcm2835-audio: Replace kmalloc with kzalloc Aishwarya Pant
2017-03-09 13:12 ` [Outreachy kernel] " Julia Lawall
2017-03-09 10:38 ` [PATCH v5 2/7] staging: bcm2835-audio: replace null with error pointer value Aishwarya Pant
2017-03-09 13:24 ` [Outreachy kernel] " Julia Lawall
2017-03-09 18:34 ` Aishwarya Pant [this message]
2017-03-09 20:40 ` Julia Lawall
2017-03-09 10:38 ` [PATCH v5 3/7] staging: bcm2835-audio: propagate PTR_ERR value instead of -EPERM Aishwarya Pant
2017-03-09 10:38 ` [PATCH v5 4/7] staging: bcm2835-audio: use conditional only for error case Aishwarya Pant
2017-03-09 10:38 ` [PATCH v5 5/7] staging: bcm2835-audio: deallocate work when queue_work(...) fails Aishwarya Pant
2017-03-09 10:39 ` [PATCH v5 6/7] staging: bcm2835-audio: fix memory leak in bcm2835_audio_open_connection() Aishwarya Pant
2017-03-09 10:39 ` [PATCH v5 7/7] staging: bcm2835-audio: remove BUG_ON() " Aishwarya Pant
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=20170309183432.GA15683@aishwarya \
--to=aishpant@gmail.com \
--cc=julia.lawall@lip6.fr \
--cc=outreachy-kernel@googlegroups.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.