All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@iki.fi>
To: Tomasz Figa <tfiga@google.com>
Cc: Hans Verkuil <hverkuil@xs4all.nl>,
	Linux Media Mailing List <linux-media@vger.kernel.org>,
	Hans Verkuil <hans.verkuil@cisco.com>
Subject: Re: [RFCv11 PATCH 05/29] media-request: add request ioctls
Date: Thu, 12 Apr 2018 10:35:04 +0300	[thread overview]
Message-ID: <20180412073504.5mggdps4os3vqv6r@valkosipuli.retiisi.org.uk> (raw)
In-Reply-To: <CAAFQd5ABOWjj9esLBxrOV_b8edv5_-VSCZNp6iZYTbUVeP9Xqw@mail.gmail.com>

Hi Tomasz,

On Tue, Apr 10, 2018 at 08:59:23AM +0000, Tomasz Figa wrote:
> Hi Hans,
> 
> On Mon, Apr 9, 2018 at 11:21 PM Hans Verkuil <hverkuil@xs4all.nl> wrote:
> 
> > From: Hans Verkuil <hans.verkuil@cisco.com>
> 
> > Implement the MEDIA_REQUEST_IOC_QUEUE and MEDIA_REQUEST_IOC_REINIT
> > ioctls.
> 
> > Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> > ---
> >   drivers/media/media-request.c | 80
> +++++++++++++++++++++++++++++++++++++++++--
> >   1 file changed, 78 insertions(+), 2 deletions(-)
> 
> > diff --git a/drivers/media/media-request.c b/drivers/media/media-request.c
> > index dffc290e4ada..27739ff7cb09 100644
> > --- a/drivers/media/media-request.c
> > +++ b/drivers/media/media-request.c
> > @@ -118,10 +118,86 @@ static unsigned int media_request_poll(struct file
> *filp,
> >          return 0;
> >   }
> 
> > +static long media_request_ioctl_queue(struct media_request *req)
> > +{
> > +       struct media_device *mdev = req->mdev;
> > +       unsigned long flags;
> > +       int ret = 0;
> > +
> > +       dev_dbg(mdev->dev, "request: queue %s\n", req->debug_str);
> > +
> > +       spin_lock_irqsave(&req->lock, flags);
> > +       if (req->state != MEDIA_REQUEST_STATE_IDLE) {
> > +               dev_dbg(mdev->dev,
> > +                       "request: unable to queue %s, request in state
> %s\n",
> > +                       req->debug_str,
> media_request_state_str(req->state));
> > +               spin_unlock_irqrestore(&req->lock, flags);
> > +               return -EINVAL;
> 
> nit: Perhaps -EBUSY? (vb2 returns -EINVAL, though, but IMHO it doesn't
> really represent the real error too closely.)
> 
> > +       }
> > +       req->state = MEDIA_REQUEST_STATE_QUEUEING;
> > +
> > +       spin_unlock_irqrestore(&req->lock, flags);
> > +
> > +       /*
> > +        * Ensure the request that is validated will be the one that gets
> queued
> > +        * next by serialising the queueing process.
> > +        */
> > +       mutex_lock(&mdev->req_queue_mutex);
> > +
> > +       ret = mdev->ops->req_queue(req);
> > +       spin_lock_irqsave(&req->lock, flags);
> > +       req->state = ret ? MEDIA_REQUEST_STATE_IDLE :
> MEDIA_REQUEST_STATE_QUEUED;
> > +       spin_unlock_irqrestore(&req->lock, flags);
> > +       mutex_unlock(&mdev->req_queue_mutex);
> > +
> > +       if (ret) {
> > +               dev_dbg(mdev->dev, "request: can't queue %s (%d)\n",
> > +                       req->debug_str, ret);
> > +       } else {
> > +               media_request_get(req);
> 
> I'm not convinced that this is the right place to take a reference. IMHO
> whoever saves a pointer to the request in its own internal data (the
> ->req_queue() callback?), should also grab a reference before doing so. Not
> a strong objection, though, if we clearly document this, so that whoever
> implements ->req_queue() callback can do the right thing.

The framework will also release that reference once the request is
complete. In my opinion it's perfectly reasonable to do this in the
framework; moving things to frameworks that do not need to be done in
drivers generally reduces bugs and makes drivers more maintainable. Albeit
this is a minor matter in this respect.

Hans: the reference must be taken before the request is queued: otherwise
it is possible that the driver completes the request before the reference
is taken here. That would mean the request might have been already released
by the time of getting a refenrece to it.

> 
> > +       }
> > +
> > +       return ret;
> > +}
> > +
> > +static long media_request_ioctl_reinit(struct media_request *req)
> > +{
> > +       struct media_device *mdev = req->mdev;
> > +       unsigned long flags;
> > +
> > +       spin_lock_irqsave(&req->lock, flags);
> > +       if (req->state != MEDIA_REQUEST_STATE_IDLE &&
> > +           req->state != MEDIA_REQUEST_STATE_COMPLETE) {
> > +               dev_dbg(mdev->dev,
> > +                       "request: %s not in idle or complete state,
> cannot reinit\n",
> > +                       req->debug_str);
> > +               spin_unlock_irqrestore(&req->lock, flags);
> > +               return -EINVAL;
> 
> nit: Perhaps -EBUSY? (Again vb2 would return -EINVAL...)

I agree on both return values.

-- 
Regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi

  reply	other threads:[~2018-04-12  7:35 UTC|newest]

Thread overview: 135+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-09 14:19 [RFCv11 PATCH 00/29] Request API Hans Verkuil
2018-04-09 14:19 ` [RFCv11 PATCH 01/29] v4l2-device.h: always expose mdev Hans Verkuil
2018-04-17  4:34   ` Alexandre Courbot
2018-04-09 14:19 ` [RFCv11 PATCH 02/29] uapi/linux/media.h: add request API Hans Verkuil
2018-04-10  5:26   ` Tomasz Figa
2018-04-23  9:55     ` Hans Verkuil
2018-04-10  9:38   ` Mauro Carvalho Chehab
2018-04-10 11:00     ` Sakari Ailus
2018-04-23 11:41       ` Hans Verkuil
2018-04-23 13:32         ` Mauro Carvalho Chehab
2018-04-17  4:34   ` Alexandre Courbot
2018-04-09 14:20 ` [RFCv11 PATCH 03/29] media-request: allocate media requests Hans Verkuil
2018-04-10  5:35   ` Tomasz Figa
2018-04-10  9:54     ` Mauro Carvalho Chehab
2018-04-23  9:59     ` Hans Verkuil
2018-04-10  9:52   ` Mauro Carvalho Chehab
2018-04-10 11:14     ` Sakari Ailus
2018-04-11 10:13       ` Mauro Carvalho Chehab
2018-04-23  9:46         ` Hans Verkuil
2018-04-23 11:49     ` Hans Verkuil
2018-04-23 13:35       ` Mauro Carvalho Chehab
2018-04-17  4:34   ` Alexandre Courbot
2018-04-09 14:20 ` [RFCv11 PATCH 04/29] media-request: core request support Hans Verkuil
2018-04-10  8:21   ` Tomasz Figa
2018-04-10 13:04     ` Sakari Ailus
2018-04-23 11:24     ` Hans Verkuil
2018-04-23 12:14       ` Hans Verkuil
2018-04-10 10:32   ` Mauro Carvalho Chehab
2018-04-10 12:32     ` Sakari Ailus
2018-04-10 14:51       ` Mauro Carvalho Chehab
2018-04-11 13:21         ` Sakari Ailus
2018-04-11 13:49           ` Mauro Carvalho Chehab
2018-04-11 15:02             ` Sakari Ailus
2018-04-11 15:17               ` Mauro Carvalho Chehab
2018-04-11 15:35                 ` Sakari Ailus
2018-04-11 16:13                   ` Mauro Carvalho Chehab
2018-04-12  7:11                     ` Sakari Ailus
2018-04-23 12:43                       ` Hans Verkuil
2018-05-07 10:05                         ` Sakari Ailus
2018-04-23 12:23     ` Hans Verkuil
2018-04-23 14:07       ` Mauro Carvalho Chehab
2018-04-10 12:17   ` Sakari Ailus
2018-04-17  4:35   ` Alexandre Courbot
2018-04-23 14:28     ` Hans Verkuil
2018-04-09 14:20 ` [RFCv11 PATCH 05/29] media-request: add request ioctls Hans Verkuil
2018-04-10  8:59   ` Tomasz Figa
2018-04-12  7:35     ` Sakari Ailus [this message]
2018-04-23 12:40       ` Hans Verkuil
2018-04-23 11:34     ` Hans Verkuil
2018-04-10 10:57   ` Mauro Carvalho Chehab
2018-04-12 10:40     ` Sakari Ailus
2018-04-23 13:45       ` Hans Verkuil
2018-04-12  7:31   ` Sakari Ailus
2018-04-09 14:20 ` [RFCv11 PATCH 06/29] media-request: add media_request_find Hans Verkuil
2018-04-10 11:04   ` Mauro Carvalho Chehab
2018-04-12 10:52     ` Sakari Ailus
2018-04-12 12:08   ` Sakari Ailus
2018-04-23 13:50     ` Hans Verkuil
2018-04-09 14:20 ` [RFCv11 PATCH 07/29] media-request: add media_request_object_find Hans Verkuil
2018-04-10 11:07   ` Mauro Carvalho Chehab
2018-04-10 11:10     ` Hans Verkuil
2018-04-12 12:23   ` Sakari Ailus
2018-04-23 13:55     ` Hans Verkuil
2018-04-17  4:36   ` Alexandre Courbot
2018-04-23 14:32     ` Hans Verkuil
2018-04-09 14:20 ` [RFCv11 PATCH 08/29] videodev2.h: add request_fd field to v4l2_ext_controls Hans Verkuil
2018-04-10 11:11   ` Mauro Carvalho Chehab
2018-04-12 12:24   ` Sakari Ailus
2018-04-09 14:20 ` [RFCv11 PATCH 09/29] videodev2.h: add V4L2_CTRL_FLAG_IN_REQUEST Hans Verkuil
2018-04-09 14:20 ` [RFCv11 PATCH 10/29] v4l2-ctrls: v4l2_ctrl_add_handler: add from_other_dev Hans Verkuil
2018-04-10 11:42   ` Mauro Carvalho Chehab
2018-04-12 13:35   ` Sakari Ailus
2018-04-09 14:20 ` [RFCv11 PATCH 11/29] v4l2-ctrls: prepare internal structs for request API Hans Verkuil
2018-04-09 14:20 ` [RFCv11 PATCH 12/29] v4l2-ctrls: alloc memory for p_req Hans Verkuil
2018-04-10  9:32   ` Tomasz Figa
2018-04-10 13:57     ` Mauro Carvalho Chehab
2018-04-23 11:39     ` Hans Verkuil
2018-04-09 14:20 ` [RFCv11 PATCH 13/29] v4l2-ctrls: use ref in helper instead of ctrl Hans Verkuil
2018-04-10 12:47   ` Mauro Carvalho Chehab
2018-04-09 14:20 ` [RFCv11 PATCH 14/29] v4l2-ctrls: add core request support Hans Verkuil
2018-04-11  8:37   ` Paul Kocialkowski
2018-04-11  9:43   ` Tomasz Figa
2018-04-23  9:23     ` Hans Verkuil
2018-04-09 14:20 ` [RFCv11 PATCH 15/29] v4l2-ctrls: support g/s_ext_ctrls for requests Hans Verkuil
2018-04-10 13:00   ` Mauro Carvalho Chehab
2018-04-09 14:20 ` [RFCv11 PATCH 16/29] videodev2.h: Add request_fd field to v4l2_buffer Hans Verkuil
2018-04-09 14:20 ` [RFCv11 PATCH 17/29] vb2: store userspace data in vb2_v4l2_buffer Hans Verkuil
2018-04-09 15:11   ` Kieran Bingham
2018-04-23  9:53     ` Hans Verkuil
2018-04-10 13:32   ` Mauro Carvalho Chehab
2018-04-09 14:20 ` [RFCv11 PATCH 18/29] videobuf2-core: embed media_request_object Hans Verkuil
2018-04-09 14:20 ` [RFCv11 PATCH 19/29] videobuf2-core: integrate with media requests Hans Verkuil
2018-04-12  8:13   ` Tomasz Figa
2018-04-23 12:49     ` Hans Verkuil
2018-04-09 14:20 ` [RFCv11 PATCH 20/29] videobuf2-v4l2: " Hans Verkuil
2018-04-10 13:52   ` Mauro Carvalho Chehab
2018-04-17  4:36   ` Alexandre Courbot
2018-04-23 14:53     ` Hans Verkuil
2018-04-09 14:20 ` [RFCv11 PATCH 21/29] videobuf2-core: add vb2_core_request_has_buffers Hans Verkuil
2018-04-10 13:53   ` Mauro Carvalho Chehab
2018-04-09 14:20 ` [RFCv11 PATCH 22/29] videobuf2-v4l2: add vb2_request_queue helper Hans Verkuil
2018-04-12  8:29   ` Tomasz Figa
2018-04-23 12:51     ` Hans Verkuil
2018-04-09 14:20 ` [RFCv11 PATCH 23/29] videobuf2-v4l2: export request_fd Hans Verkuil
2018-04-10 13:59   ` Mauro Carvalho Chehab
2018-04-09 14:20 ` [RFCv11 PATCH 24/29] Documentation: v4l: document request API Hans Verkuil
2018-04-10 14:19   ` Mauro Carvalho Chehab
2018-04-12  8:51   ` Tomasz Figa
2018-04-09 14:20 ` [RFCv11 PATCH 25/29] media: vim2m: add media device Hans Verkuil
2018-04-12  8:54   ` Tomasz Figa
2018-04-23 13:23     ` Hans Verkuil
2018-04-17  4:37   ` Alexandre Courbot
2018-04-09 14:20 ` [RFCv11 PATCH 26/29] vim2m: use workqueue Hans Verkuil
2018-04-11 14:06   ` Paul Kocialkowski
2018-04-30 14:51     ` Hans Verkuil
2018-04-12  9:02   ` Tomasz Figa
2018-04-30 14:58     ` Hans Verkuil
2018-04-09 14:20 ` [RFCv11 PATCH 27/29] vim2m: support requests Hans Verkuil
2018-04-11 14:01   ` Paul Kocialkowski
2018-04-12  9:15   ` Tomasz Figa
2018-04-23 13:30     ` Hans Verkuil
2018-04-17  4:37   ` Alexandre Courbot
2018-04-23 15:06     ` Hans Verkuil
2018-04-17 11:42   ` Paul Kocialkowski
2018-04-23 15:10     ` Hans Verkuil
2018-04-09 14:20 ` [RFCv11 PATCH 28/29] vivid: add mc Hans Verkuil
2018-04-09 14:20 ` [RFCv11 PATCH 29/29] vivid: add request support Hans Verkuil
2018-04-10 14:31 ` [RFCv11 PATCH 00/29] Request API Mauro Carvalho Chehab
2018-04-17  4:33 ` Alexandre Courbot
2018-04-17  6:12   ` Hans Verkuil
2018-04-17  6:17     ` Alexandre Courbot
2018-04-17 11:40       ` Paul Kocialkowski
2018-04-18  2:06         ` Alexandre Courbot
2018-04-19  7:48           ` Paul Kocialkowski
2018-04-23 15:10             ` Hans Verkuil

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=20180412073504.5mggdps4os3vqv6r@valkosipuli.retiisi.org.uk \
    --to=sakari.ailus@iki.fi \
    --cc=hans.verkuil@cisco.com \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    --cc=tfiga@google.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.