From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: jacopo mondi <jacopo@jmondi.org>
Cc: Jacopo Mondi <jacopo+renesas@jmondi.org>,
magnus.damm@gmail.com, geert@glider.be, mchehab@kernel.org,
hverkuil@xs4all.nl, robh+dt@kernel.org, mark.rutland@arm.com,
linux-renesas-soc@vger.kernel.org, linux-media@vger.kernel.org,
linux-sh@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/9] v4l: platform: Add Renesas CEU driver
Date: Wed, 03 Jan 2018 13:19:44 +0200 [thread overview]
Message-ID: <4054216.2BkSFUv9xJ@avalon> (raw)
In-Reply-To: <20180103104748.GC9493@w540>
Hi Jacopo,
On Wednesday, 3 January 2018 12:47:48 EET jacopo mondi wrote:
> On Tue, Jan 02, 2018 at 03:46:27PM +0200, Laurent Pinchart wrote:
> >> +/*
> >> + * ceu_device - CEU device instance
> >> + */
> >> +struct ceu_device {
> >> + struct device *dev;
> >> + struct video_device vdev;
> >> + struct v4l2_device v4l2_dev;
> >> +
> >> + /* subdevices descriptors */
> >> + struct ceu_subdev *subdevs;
> >> + /* the subdevice currently in use */
> >> + struct ceu_subdev *sd;
> >> + unsigned int sd_index;
> >> + unsigned int num_sd;
> >> +
> >> + /* platform specific mask with all IRQ sources flagged */
> >> + u32 irq_mask;
> >> +
> >> + /* currently configured field and pixel format */
> >> + enum v4l2_field field;
> >> + struct v4l2_pix_format_mplane v4l2_pix;
> >> +
> >> + /* async subdev notification helpers */
> >> + struct v4l2_async_notifier notifier;
> >> + /* pointers to "struct ceu_subdevice -> asd" */
> >> + struct v4l2_async_subdev **asds;
> >> +
> >> + /* vb2 queue, capture buffer list and active buffer pointer */
> >> + struct vb2_queue vb2_vq;
> >> + struct list_head capture;
> >> + struct vb2_v4l2_buffer *active;
> >> + unsigned int sequence;
> >> +
> >> + /* mlock - lock device suspend/resume and videobuf2 operations */
> >
> > In my review of v1 I commented that lock documentation should explain what
> > data is protected by the lock. As my point seems not to have come across
> > it must not have been clear enough, I'll try to fix that.
> >
> > The purpose of a lock is to protect from concurrent access to a resource.
> > In device drivers resources are in most cases either in-memory data or
> > device registers. To design a good locking scheme you need to ask
> > yourself what resources can be accessed concurrently, and then protect
> > all accesses to those resources using locking primitives. Some accesses
> > don't need to be protected (for instance it's common to initialize
> > structure fields in the probe function where no concurrent access from
> > userspace can occur as device nodes are not registered yet), and locking
> > can then be omitted in a case by case basis.
> >
> > Lock documentation is essential to understand the locking scheme and
> > should explain what resources are protected by the lock. It's tempting
> > (because it's easy) to instead focus on what code sections the lock
> > covers, but that's not how the locking scheme should be designed, and will
> > eventually be prone to bugs leading to race conditions.
>
> Thanks, I got this, but that lock is used to protect concurrent
> accesses to suspend/resume (and thus interface reset) and is used as
> vb2 queue lock. I can mention it guards concurrent interfaces resets,
> but I don't see it being that much different from what I already
> mentioned.
You're right, in this case the way videobuf2 operates makes it difficult to
find out what the lock protects exactly. That's why I don't like locks that
cover code sections instead of protecting data, they're much harder to check
for correctness. There's nothing you can do about it.
> > Obviously a lock will end up preventing multiple code sections from
> > running at the same time, but that's the consequence of the locking
> > scheme, it shouldn't be its cause.
> >
> >> + struct mutex mlock;
> >> +
> >> + /* lock - lock access to capture buffer queue and active buffer */
> >> + spinlock_t lock;
> >> +
> >> + /* base - CEU memory base address */
> >> + void __iomem *base;
> >> +};
[snip]
> >> +/* CEU Capture Operations */
> >
> > Just curious, why have you replaced the block comments by single-line
> > comments ? I pointed out that the format was wrong as you started them
> > with /** and they were not kerneldoc, but I have nothing against
> > splitting the code in sections with headers such as
> >
> > /* -----------------------------------------------------------------------
> > * CEU Capture Operations
> > */
> >
> > as I do so routinely in my drivers. If that's your preferred style and you
> > thought I asked for a change you can switch back, if you prefer
> > single-line comments that's fine with me too.
>
> Yes I borrowed that commenting style from other Renesas drivers you
> wrote, so I went for it for consistency.
>
> I recently read about some discussions on block comments, when Mauro
> was trying to replace /***...***/ block comments with a script, and
> I had the feeling there's not that much love for block comments around
> here, and I also find them a bit invasive.
>
> I used the
> /* --- Code section --- */
> style in the past which I find is a good balance between
> intrusiveness and noticeability but I don't want to introduce
> yet-another-comment-style so I went for single line and that's it.
I think this is a matter of personal preference and best left to the driver
author. Of course minimizing the number of style differences is a good idea,
but I don't see anything wrong with a block comment (quite obviously as I use
them ;-)) or your /* --- Code section --- */ comment. I find that having a
comment that stands out improves readability in long source files. It's up to
you.
> > [snip]
> >
> >> +/*
> >> + * ceu_calc_plane_sizes() - Fill per-plane 'struct
> >> v4l2_plane_pix_format'
> >> + * information according to the currently configured
> >> + * pixel format.
> >> + * @ceu_device: CEU device.
> >> + * @ceu_fmt: Active image format.
> >> + * @pix: Pixel format information (store line width and image sizes)
> >> + *
> >> + * Returns 0 for success.
> >> + */
> >> +static int ceu_calc_plane_sizes(struct ceu_device *ceudev,
> >> + const struct ceu_fmt *ceu_fmt,
> >> + struct v4l2_pix_format_mplane *pix)
> >> +{
> >> + unsigned int bpl, szimage;
> >> +
> >> + switch (pix->pixelformat) {
> >> + case V4L2_PIX_FMT_YUYV:
> >> + pix->num_planes = 1;
> >> + bpl = pix->width * ceu_fmt->bpp / 8;
> >> + szimage = pix->height * bpl;
> >> + ceu_update_plane_sizes(&pix->plane_fmt[0], bpl, szimage);
> >> + break;
> >> +
> >> + case V4L2_PIX_FMT_NV16:
> >> + case V4L2_PIX_FMT_NV61:
> >> + pix->num_planes = 2;
> >> + bpl = pix->width;
> >> + szimage = pix->height * pix->width;
> >> + ceu_update_plane_sizes(&pix->plane_fmt[0], bpl, szimage);
> >> + ceu_update_plane_sizes(&pix->plane_fmt[1], bpl, szimage);
> >> + break;
> >> +
> >> + case V4L2_PIX_FMT_NV12:
> >> + case V4L2_PIX_FMT_NV21:
> >> + pix->num_planes = 2;
> >> + bpl = pix->width;
> >> + szimage = pix->height * pix->width;
> >> + ceu_update_plane_sizes(&pix->plane_fmt[0], bpl, szimage);
> >> + ceu_update_plane_sizes(&pix->plane_fmt[1], bpl, szimage / 2);
> >> + break;
> >> +
> >> + default:
> >> + pix->num_planes = 0;
> >> + dev_err(ceudev->dev,
> >> + "Format 0x%x not supported\n", pix->pixelformat);
> >> + return -EINVAL;
> >
> > I think you can remove the default case as ceu_try_fmt() should have
> > validated the format already. The compiler will then likely warn so you
> > need to keep a default cause, but it will never be hit, so it can default
> > to any format you want. The function can then be turned into a void.
>
> Yes, that was only to silence the compiler actually...
Which has to be done, but let's try to not add dead code :-) Putting the
default case right below the pixel format that the try format function
defaults to should be enough for instance.
> >> + }
> >> +
> >> + return 0;
> >> +}
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2018-01-03 11:19 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-28 14:01 [PATCH v2 0/9] Renesas Capture Engine Unit (CEU) V4L2 driver Jacopo Mondi
[not found] ` <1514469681-15602-1-git-send-email-jacopo+renesas-AW8dsiIh9cEdnm+yROfE0A@public.gmane.org>
2017-12-28 14:01 ` [PATCH v2 1/9] dt-bindings: media: Add Renesas CEU bindings Jacopo Mondi
2018-01-02 9:34 ` Geert Uytterhoeven
2018-01-02 11:45 ` Laurent Pinchart
2018-01-03 8:49 ` jacopo mondi
2018-01-03 11:22 ` Laurent Pinchart
2017-12-28 14:01 ` [PATCH v2 2/9] include: media: Add Renesas CEU driver interface Jacopo Mondi
2018-01-02 11:50 ` Laurent Pinchart
2018-01-03 9:00 ` jacopo mondi
2017-12-28 14:01 ` [PATCH v2 3/9] v4l: platform: Add Renesas CEU driver Jacopo Mondi
[not found] ` <1514469681-15602-4-git-send-email-jacopo+renesas-AW8dsiIh9cEdnm+yROfE0A@public.gmane.org>
2018-01-02 13:46 ` Laurent Pinchart
2018-01-03 10:47 ` jacopo mondi
2018-01-03 11:19 ` Laurent Pinchart [this message]
2017-12-28 14:01 ` [PATCH v2 4/9] ARM: dts: r7s72100: Add Capture Engine Unit (CEU) Jacopo Mondi
[not found] ` <1514469681-15602-5-git-send-email-jacopo+renesas-AW8dsiIh9cEdnm+yROfE0A@public.gmane.org>
2018-01-02 9:35 ` Geert Uytterhoeven
2018-01-02 13:54 ` Laurent Pinchart
2017-12-28 14:01 ` [PATCH v2 5/9] arch: sh: migor: Use new renesas-ceu camera driver Jacopo Mondi
[not found] ` <1514469681-15602-6-git-send-email-jacopo+renesas-AW8dsiIh9cEdnm+yROfE0A@public.gmane.org>
2017-12-30 19:04 ` kbuild test robot
2018-01-02 15:27 ` Laurent Pinchart
2017-12-28 14:01 ` [PATCH v2 6/9] v4l: i2c: Copy ov772x soc_camera sensor driver Jacopo Mondi
2017-12-29 12:47 ` Philippe Ombredanne
2018-01-02 9:00 ` jacopo mondi
2017-12-28 14:01 ` [PATCH v2 7/9] media: i2c: ov772x: Remove soc_camera dependencies Jacopo Mondi
2018-01-02 15:44 ` Laurent Pinchart
2018-01-03 15:44 ` jacopo mondi
2018-01-03 15:49 ` Laurent Pinchart
2018-01-03 16:24 ` jacopo mondi
2017-12-28 14:01 ` [PATCH v2 8/9] v4l: i2c: Copy tw9910 soc_camera sensor driver Jacopo Mondi
2017-12-28 14:01 ` [PATCH v2 9/9] media: i2c: tw9910: Remove soc_camera dependencies Jacopo Mondi
2018-01-02 15:50 ` Laurent Pinchart
2018-01-03 16:24 ` jacopo mondi
2018-01-03 16:41 ` Fabio Estevam
[not found] ` <CAOMZO5CjrXfzum7JgimGqvnM7kjMyZZdtpEhvYwO-DLnig=uMQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-01-03 17:13 ` jacopo mondi
2018-01-03 17:27 ` Fabio Estevam
2018-01-03 17:37 ` jacopo mondi
2018-01-03 18:14 ` Fabio Estevam
2018-01-03 19:34 ` jacopo mondi
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=4054216.2BkSFUv9xJ@avalon \
--to=laurent.pinchart@ideasonboard.com \
--cc=devicetree@vger.kernel.org \
--cc=geert@glider.be \
--cc=hverkuil@xs4all.nl \
--cc=jacopo+renesas@jmondi.org \
--cc=jacopo@jmondi.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=linux-sh@vger.kernel.org \
--cc=magnus.damm@gmail.com \
--cc=mark.rutland@arm.com \
--cc=mchehab@kernel.org \
--cc=robh+dt@kernel.org \
/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).