linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: linux-media@vger.kernel.org, Tsuchiya Yuto <kitakar@gmail.com>,
	bingbu.cao@intel.com, Yong Zhi <yong.zhi@intel.com>,
	Tianshu Qiu <tian.shu.qiu@intel.com>
Subject: Re: [PATCH 2/3] ipu3-cio2: Serialise access to pad format
Date: Fri, 9 Oct 2020 13:39:29 +0300	[thread overview]
Message-ID: <20201009103929.GA3935@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20201009094347.GQ26842@paasikivi.fi.intel.com>

Hi Sakari,

On Fri, Oct 09, 2020 at 12:43:47PM +0300, Sakari Ailus wrote:
> On Fri, Oct 09, 2020 at 03:44:12AM +0300, Laurent Pinchart wrote:
> > On Thu, Oct 08, 2020 at 11:47:46PM +0300, Sakari Ailus wrote:
> > > Pad format can be accessed from user space. Serialise access to it.
> > > 
> > > Fixes: c2a6a07afe4a ("media: intel-ipu3: cio2: add new MIPI-CSI2 driver")
> > > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> > > ---
> > >  drivers/media/pci/intel/ipu3/ipu3-cio2.c | 11 +++++++++++
> > >  drivers/media/pci/intel/ipu3/ipu3-cio2.h |  1 +
> > >  2 files changed, 12 insertions(+)
> > > 
> > > diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c
> > > index afa472026ba4..9c7b527a8800 100644
> > > --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c
> > > +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c
> > > @@ -1233,11 +1233,15 @@ static int cio2_subdev_get_fmt(struct v4l2_subdev *sd,
> > >  {
> > >  	struct cio2_queue *q = container_of(sd, struct cio2_queue, subdev);
> > >  
> > > +	mutex_lock(&q->subdev_lock);
> > > +
> > >  	if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
> > >  		fmt->format = *v4l2_subdev_get_try_format(sd, cfg, fmt->pad);
> > >  	else
> > >  		fmt->format = q->subdev_fmt;
> > >  
> > > +	mutex_unlock(&q->subdev_lock);
> > > +
> > >  	return 0;
> > >  }
> > >  
> > > @@ -1261,6 +1265,8 @@ static int cio2_subdev_set_fmt(struct v4l2_subdev *sd,
> > >  	if (fmt->pad == CIO2_PAD_SOURCE)
> > >  		return cio2_subdev_get_fmt(sd, cfg, fmt);
> > >  
> > > +	mutex_lock(&q->subdev_lock);
> > > +
> > >  	if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
> > >  		*v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format;
> > >  	} else {
> > > @@ -1271,6 +1277,8 @@ static int cio2_subdev_set_fmt(struct v4l2_subdev *sd,
> > >  		fmt->format = q->subdev_fmt;
> > >  	}
> > 
> > Not a candidate for this patch, but this should restrict the pixel
> > format and size to supported values.
> 
> Yes.
> 
> > 
> > >  
> > > +	mutex_unlock(&q->subdev_lock);
> > > +
> > >  	return 0;
> > >  }
> > >  
> > > @@ -1529,6 +1537,7 @@ static int cio2_queue_init(struct cio2_device *cio2, struct cio2_queue *q)
> > >  
> > >  	/* Initialize miscellaneous variables */
> > >  	mutex_init(&q->lock);
> > > +	mutex_init(&q->subdev_lock);
> > >  
> > >  	/* Initialize formats to default values */
> > >  	fmt = &q->subdev_fmt;
> > > @@ -1646,6 +1655,7 @@ static int cio2_queue_init(struct cio2_device *cio2, struct cio2_queue *q)
> > >  	cio2_fbpt_exit(q, &cio2->pci_dev->dev);
> > >  fail_fbpt:
> > >  	mutex_destroy(&q->lock);
> > > +	mutex_destroy(&q->subdev_lock);
> > >  
> > >  	return r;
> > >  }
> > > @@ -1658,6 +1668,7 @@ static void cio2_queue_exit(struct cio2_device *cio2, struct cio2_queue *q)
> > >  	media_entity_cleanup(&q->subdev.entity);
> > >  	cio2_fbpt_exit(q, &cio2->pci_dev->dev);
> > >  	mutex_destroy(&q->lock);
> > > +	mutex_destroy(&q->subdev_lock);
> > >  }
> > >  
> > >  static int cio2_queues_init(struct cio2_device *cio2)
> > > diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.h b/drivers/media/pci/intel/ipu3/ipu3-cio2.h
> > > index 549b08f88f0c..df0247326a1d 100644
> > > --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.h
> > > +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.h
> > > @@ -335,6 +335,7 @@ struct cio2_queue {
> > >  
> > >  	/* Subdev, /dev/v4l-subdevX */
> > >  	struct v4l2_subdev subdev;
> > > +	struct mutex subdev_lock;
> > 
> > Can you add a small comment to tell which field(s) this lock protects ?
> 
> How about:
> 
> 	/* Serialise access to subdev_fmt field */

That's perfect :-)

> Currently it's just that, but I feel locking in this driver would generally
> benefit from refactoring. That can wait a little though as it's not an
> acute problem.

Sure.

> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > 
> > >  	struct media_pad subdev_pads[CIO2_PADS];
> > >  	struct v4l2_mbus_framefmt subdev_fmt;
> > >  	atomic_t frame_sequence;

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2020-10-09 10:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-08 20:47 [PATCH 0/3] ipu3-cio2 format fixes Sakari Ailus
2020-10-08 20:47 ` [PATCH 1/3] ipu3-cio2: Return actual subdev format Sakari Ailus
2020-10-09  0:39   ` Laurent Pinchart
2020-10-08 20:47 ` [PATCH 2/3] ipu3-cio2: Serialise access to pad format Sakari Ailus
2020-10-09  0:44   ` Laurent Pinchart
2020-10-09  9:43     ` Sakari Ailus
2020-10-09 10:39       ` Laurent Pinchart [this message]
2020-10-09 16:17   ` Andy Shevchenko
2020-10-08 20:47 ` [PATCH 3/3] ipu3-cio2: Only allow setting valid mbus codes Sakari Ailus
2020-10-09  0:49   ` Laurent Pinchart
2020-10-09  9:44     ` 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=20201009103929.GA3935@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=bingbu.cao@intel.com \
    --cc=kitakar@gmail.com \
    --cc=linux-media@vger.kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=tian.shu.qiu@intel.com \
    --cc=yong.zhi@intel.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).