From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: linux-media@vger.kernel.org
Cc: laurent.pinchart@ideasonboard.com, hverkuil@xs4all.nl,
mchehab@osg.samsung.com
Subject: [RFC v2 03/21] media: Prevent queueing queued requests
Date: Tue, 24 May 2016 19:47:13 +0300 [thread overview]
Message-ID: <1464108451-28142-4-git-send-email-sakari.ailus@linux.intel.com> (raw)
In-Reply-To: <1464108451-28142-1-git-send-email-sakari.ailus@linux.intel.com>
Verify that the request state is IDLE before queueing it. Also mark
requests queued when they're queued, and return the request to IDLE if
queueing it failed.
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
drivers/media/media-device.c | 55 +++++++++++++++++++++++++++++++++++++-------
1 file changed, 47 insertions(+), 8 deletions(-)
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 7781c49..247587b 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -189,6 +189,47 @@ static void media_device_request_delete(struct media_device *mdev,
media_device_request_put(req);
}
+static int media_device_request_queue_apply(
+ struct media_device *mdev, struct media_device_request *req,
+ int (*fn)(struct media_device *mdev,
+ struct media_device_request *req), bool queue)
+{
+ char *str = queue ? "queue" : "apply";
+ unsigned long flags;
+ int rval = 0;
+
+ if (!fn)
+ return -ENOSYS;
+
+ spin_lock_irqsave(&mdev->req_lock, flags);
+ if (req->state != MEDIA_DEVICE_REQUEST_STATE_IDLE) {
+ rval = -EINVAL;
+ dev_dbg(mdev->dev,
+ "request: unable to %s %u, request in state %s\n",
+ str, req->id, request_state(req->state));
+ } else {
+ req->state = MEDIA_DEVICE_REQUEST_STATE_QUEUED;
+ }
+ spin_unlock_irqrestore(&mdev->req_lock, flags);
+
+ if (rval)
+ return rval;
+
+ rval = fn(mdev, req);
+ if (rval) {
+ spin_lock_irqsave(&mdev->req_lock, flags);
+ req->state = MEDIA_DEVICE_REQUEST_STATE_IDLE;
+ spin_unlock_irqrestore(&mdev->req_lock, flags);
+ dev_dbg(mdev->dev,
+ "request: can't %s %u\n", str, req->id);
+ } else {
+ dev_dbg(mdev->dev,
+ "request: %s %u\n", str, req->id);
+ }
+
+ return rval;
+}
+
static long media_device_request_cmd(struct media_device *mdev,
struct file *filp,
struct media_request_cmd *cmd)
@@ -216,17 +257,15 @@ static long media_device_request_cmd(struct media_device *mdev,
break;
case MEDIA_REQ_CMD_APPLY:
- if (!mdev->ops->req_apply)
- return -ENOSYS;
-
- ret = mdev->ops->req_apply(mdev, req);
+ ret = media_device_request_queue_apply(mdev, req,
+ mdev->ops->req_apply,
+ false);
break;
case MEDIA_REQ_CMD_QUEUE:
- if (!mdev->ops->req_queue)
- return -ENOSYS;
-
- ret = mdev->ops->req_queue(mdev, req);
+ ret = media_device_request_queue_apply(mdev, req,
+ mdev->ops->req_queue,
+ true);
break;
default:
--
1.9.1
next prev parent reply other threads:[~2016-05-24 16:50 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-24 16:47 [RFC v2 0/21] Media request API Sakari Ailus
2016-05-24 16:47 ` [RFC v2 01/21] media: Add " Sakari Ailus
2016-05-24 16:47 ` [RFC v2 02/21] media: Add media device request state Sakari Ailus
2016-05-24 16:47 ` Sakari Ailus [this message]
2016-05-24 16:47 ` [RFC v2 04/21] media: Only requests in IDLE state may be deleted Sakari Ailus
2016-05-24 16:47 ` [RFC v2 05/21] media: Add media_device_request_complete() to mark requests complete Sakari Ailus
2016-05-24 16:47 ` [RFC v2 06/21] media: Add per-entity request data support Sakari Ailus
2016-05-24 16:47 ` [RFC v2 07/21] videodev2.h: Add request field to v4l2_buffer Sakari Ailus
2016-05-24 16:47 ` [RFC v2 08/21] videodev2.h: Add request field to v4l2_pix_format_mplane Sakari Ailus
2016-05-24 16:47 ` [RFC v2 09/21] v4l2-subdev.h: Add request field to format and selection structures Sakari Ailus
2016-05-24 16:47 ` [RFC v2 10/21] v4l: Support the request API in format operations Sakari Ailus
2016-05-24 16:47 ` [RFC v2 11/21] v4l: subdev: Support the request API in format and selection operations Sakari Ailus
2016-05-24 16:47 ` [RFC v2 12/21] vb2: Add allow_requests flag Sakari Ailus
2016-05-24 16:47 ` [RFC v2 13/21] media: Add MEDIA_IOC_DQEVENT Sakari Ailus
2016-05-24 16:47 ` [RFC v2 14/21] media: Make events on request completion optional, disabled by default Sakari Ailus
2016-05-24 16:47 ` [RFC v2 15/21] media: Add poll support Sakari Ailus
2016-05-24 16:47 ` [RFC v2 16/21] DocBook: media: Document the media request API Sakari Ailus
2016-05-24 16:47 ` [RFC v2 17/21] DocBook: media: Document the V4L2 " Sakari Ailus
2016-05-24 16:47 ` [RFC v2 18/21] DocBook: media: Document the subdev selection API Sakari Ailus
2016-05-24 16:47 ` [RFC v2 19/21] DocBook: media: Document the V4L2 subdev request API Sakari Ailus
2016-05-24 16:47 ` [RFC v2 20/21] DocBook: media: Document media events (MEDIA_IOC_DQEVENT IOCTL) Sakari Ailus
2016-05-24 16:47 ` [RFC v2 21/21] DocBook: media: Document request flags Sakari Ailus
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=1464108451-28142-4-git-send-email-sakari.ailus@linux.intel.com \
--to=sakari.ailus@linux.intel.com \
--cc=hverkuil@xs4all.nl \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@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).