From: Mauro Carvalho Chehab <mchehab@s-opensource.com>
To: Shuah Khan <shuah@kernel.org>
Cc: Linux Media Mailing List <linux-media@vger.kernel.org>,
Mauro Carvalho Chehab <mchehab@infradead.org>,
Max Kellermann <max.kellermann@gmail.com>,
Colin Ian King <colin.king@canonical.com>,
Shuah Khan <shuahkh@osg.samsung.com>
Subject: Re: [PATCH 1/6] media: dvb_frontend: cleanup dvb_frontend_ioctl_properties()
Date: Wed, 20 Sep 2017 17:27:03 -0300 [thread overview]
Message-ID: <20170920172703.6a10ae61@recife.lan> (raw)
In-Reply-To: <bc18d8a6-cf50-3257-71b0-d90e7fb5ba25@kernel.org>
Em Wed, 20 Sep 2017 14:11:39 -0600
Shuah Khan <shuah@kernel.org> escreveu:
> On 09/19/2017 07:42 AM, Mauro Carvalho Chehab wrote:
> > Use a switch() on this function, just like on other ioctl
> > handlers and handle parameters inside each part of the
> > switch.
> >
> > That makes it easier to integrate with the already existing
> > ioctl handler function.
> >
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
>
> The change looks good. Couple of comments below:
>
> > ---
> > drivers/media/dvb-core/dvb_frontend.c | 83 +++++++++++++++++++++--------------
> > 1 file changed, 51 insertions(+), 32 deletions(-)
> >
> > diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c
> > index 8abe4f541a36..725cb1c8a088 100644
> > --- a/drivers/media/dvb-core/dvb_frontend.c
> > +++ b/drivers/media/dvb-core/dvb_frontend.c
> > @@ -1971,21 +1971,25 @@ static int dvb_frontend_ioctl_properties(struct file *file,
> > struct dvb_frontend *fe = dvbdev->priv;
> > struct dvb_frontend_private *fepriv = fe->frontend_priv;
> > struct dtv_frontend_properties *c = &fe->dtv_property_cache;
> > - int err = 0;
> > -
> > - struct dtv_properties *tvps = parg;
> > - struct dtv_property *tvp = NULL;
> > - int i;
> > + int err, i;
> >
> > dev_dbg(fe->dvb->device, "%s:\n", __func__);
> >
> > - if (cmd == FE_SET_PROPERTY) {
> > - dev_dbg(fe->dvb->device, "%s: properties.num = %d\n", __func__, tvps->num);
> > - dev_dbg(fe->dvb->device, "%s: properties.props = %p\n", __func__, tvps->props);
> > + switch(cmd) {
> > + case FE_SET_PROPERTY: {
> > + struct dtv_properties *tvps = parg;
> > + struct dtv_property *tvp = NULL;
> >
> > - /* Put an arbitrary limit on the number of messages that can
> > - * be sent at once */
> > - if ((tvps->num == 0) || (tvps->num > DTV_IOCTL_MAX_MSGS))
> > + dev_dbg(fe->dvb->device, "%s: properties.num = %d\n",
> > + __func__, tvps->num);
> > + dev_dbg(fe->dvb->device, "%s: properties.props = %p\n",
> > + __func__, tvps->props);
> > +
> > + /*
> > + * Put an arbitrary limit on the number of messages that can
> > + * be sent at once
> > + */
> > + if (!tvps->num || (tvps->num > DTV_IOCTL_MAX_MSGS))
> > return -EINVAL;
> >
> > tvp = memdup_user(tvps->props, tvps->num * sizeof(*tvp));
> > @@ -1994,23 +1998,34 @@ static int dvb_frontend_ioctl_properties(struct file *file,
> >
> > for (i = 0; i < tvps->num; i++) {
> > err = dtv_property_process_set(fe, tvp + i, file);
> > - if (err < 0)
> > - goto out;
> > + if (err < 0) {
> > + kfree(tvp);
> > + return err;
> > + }
> > (tvp + i)->result = err;
> > }
> >
> > if (c->state == DTV_TUNE)
> > dev_dbg(fe->dvb->device, "%s: Property cache is full, tuning\n", __func__);
> >
> > - } else if (cmd == FE_GET_PROPERTY) {
> > + kfree(tvp);
> > + break;
> > + }
> > + case FE_GET_PROPERTY: {
> > + struct dtv_properties *tvps = parg;
> > + struct dtv_property *tvp = NULL;
> > struct dtv_frontend_properties getp = fe->dtv_property_cache;
> >
> > - dev_dbg(fe->dvb->device, "%s: properties.num = %d\n", __func__, tvps->num);
> > - dev_dbg(fe->dvb->device, "%s: properties.props = %p\n", __func__, tvps->props);
> > + dev_dbg(fe->dvb->device, "%s: properties.num = %d\n",
> > + __func__, tvps->num);
> > + dev_dbg(fe->dvb->device, "%s: properties.props = %p\n",
> > + __func__, tvps->props);
> >
> > - /* Put an arbitrary limit on the number of messages that can
> > - * be sent at once */
> > - if ((tvps->num == 0) || (tvps->num > DTV_IOCTL_MAX_MSGS))
> > + /*
> > + * Put an arbitrary limit on the number of messages that can
> > + * be sent at once
> > + */
> > + if (!tvps->num || (tvps->num > DTV_IOCTL_MAX_MSGS))
> > return -EINVAL;
> >
> > tvp = memdup_user(tvps->props, tvps->num * sizeof(*tvp));
> > @@ -2025,28 +2040,32 @@ static int dvb_frontend_ioctl_properties(struct file *file,
> > */
> > if (fepriv->state != FESTATE_IDLE) {
> > err = dtv_get_frontend(fe, &getp, NULL);
> > - if (err < 0)
> > - goto out;
> > + if (err < 0) {
> > + kfree(tvp);
> > + return err;
> > + }
>
> Could avoid duplicate code keeping out logic perhaps? Is there a reason
> for removing this?
Yes. See the next patch :-)
Basically, the next patch remove dvb_frontend_ioctl_properties(), merging
it with another ioctl handler. On such handler, the error handling path
is different for each ioctl.
We might still use gotos there, but that would be messy.
>
> > }
> > for (i = 0; i < tvps->num; i++) {
> > err = dtv_property_process_get(fe, &getp, tvp + i, file);
> > - if (err < 0)
> > - goto out;
> > + if (err < 0) {
> > + kfree(tvp);
> > + return err;
> > + }
> > (tvp + i)->result = err;
> > }
> >
> > if (copy_to_user((void __user *)tvps->props, tvp,
> > tvps->num * sizeof(struct dtv_property))) {
> > - err = -EFAULT;
> > - goto out;
> > + kfree(tvp);
> > + return -EFAULT;
> > }
>
> Could avoid duplicate code keeping out logic perhaps? Is there a reason
> for removing this?
Same as above.
>
> > -
> > - } else
> > - err = -EOPNOTSUPP;
> > -
> > -out:
> > - kfree(tvp);
> > - return err;
> > + kfree(tvp);
> > + break;
> > + }
> > + default:
> > + return -ENOTSUPP;
> > + } /* switch */
> > + return 0;
> > }
> >
> > static int dtv_set_frontend(struct dvb_frontend *fe)
> >
>
> Reviewed-by: Shuah Khan <shuahkh@osg.samsung.com>
>
> thanks,
> -- Shuah
Thanks,
Mauro
prev parent reply other threads:[~2017-09-20 20:27 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-19 13:42 [PATCH 1/6] media: dvb_frontend: cleanup dvb_frontend_ioctl_properties() Mauro Carvalho Chehab
2017-09-19 13:42 ` [PATCH 2/6] media: dvb_frontend: cleanup ioctl handling logic Mauro Carvalho Chehab
2017-09-20 20:58 ` Shuah Khan
2017-09-20 21:16 ` Mauro Carvalho Chehab
2017-09-19 13:42 ` [PATCH 3/6] media: dvb_frontend: get rid of proprierty cache's state Mauro Carvalho Chehab
2017-09-20 21:08 ` Shuah Khan
2017-09-19 13:42 ` [PATCH 4/6] media: dvb_frontend.h: fix alignment at the cache properties Mauro Carvalho Chehab
2017-09-19 13:42 ` [PATCH 5/6] media: dvb_frontend: better document the -EPERM condition Mauro Carvalho Chehab
2017-09-20 21:12 ` Shuah Khan
2017-09-19 13:42 ` [PATCH 6/6] media: dvb_frontend: fix return values for FE_SET_PROPERTY Mauro Carvalho Chehab
2017-09-20 20:11 ` [PATCH 1/6] media: dvb_frontend: cleanup dvb_frontend_ioctl_properties() Shuah Khan
2017-09-20 20:27 ` Mauro Carvalho Chehab [this message]
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=20170920172703.6a10ae61@recife.lan \
--to=mchehab@s-opensource.com \
--cc=colin.king@canonical.com \
--cc=linux-media@vger.kernel.org \
--cc=max.kellermann@gmail.com \
--cc=mchehab@infradead.org \
--cc=shuah@kernel.org \
--cc=shuahkh@osg.samsung.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 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).