From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Anton Leontiev <bunder@t-25.ru>
Cc: Mauro Carvalho Chehab <m.chehab@samsung.com>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] [media] uvcvideo: Fix marking buffer erroneous in case of FID toggling
Date: Tue, 01 Apr 2014 17:24:14 +0200 [thread overview]
Message-ID: <10422468.Ah80osK73i@avalon> (raw)
In-Reply-To: <533659E2.4010001@t-25.ru>
Hi Anton,
On Saturday 29 March 2014 09:28:02 Anton Leontiev wrote:
> 28.03.2014 20:12, Laurent Pinchart пишет:
> >>>> + * Set error flag for incomplete buffer.
> >>>> + */
> >>>> +static void uvc_buffer_check_bytesused(const struct uvc_streaming
> >>>> *const stream,
> >
> > No need for the second const keyword here.
> >
> > I would have used "uvc_video_" as a prefix, to be in sync with the
> > surrounding functions. What would you think of
> > uvc_video_validate_buffer() ?
> >
> >>>> + struct uvc_buffer *const buf)
> >
> > And no need for const at all here.
> >
> >>>> +{
> >>>> + if (buf->length != buf->bytesused &&
> >>>> + !(stream->cur_format->flags & UVC_FMT_FLAG_COMPRESSED))
> >
> > The indentation is wrong here, the ! on the second line should be aligned
> > to the first 'buf' of the first line.
> >
> > If you agree with these changes I can perform them while applying, there's
> > no need to resubmit the patch.
>
> Thank you for reviewing my first patch to Linux kernel.
Thank you for submitting it :-)
> I completely agree with your changes.
>
> Just want to ask why there is no need for the second 'const' after pointer
> character '*'? I thought it marks pointer itself as constant for type-
> checking opposite to first 'const', which marks memory it points to as
> constant for type-checking.
Your understanding is correct (as far as I know).
> I understand that the function is simple enough to verify it by hand but
> it's better to add more information for automatic checking.
>
> Is there any guidelines on 'const' keyword usage in Linux kernel code?
Marking the memory pointed to by the pointer as const ensures that the
function won't modify memory that the caller thought wouldn't be modified. It
thus serves as a contract between the caller and the callee, enforced by the
compiler.
Marking the pointer as const, on the other hand, only affects the function
implementation, without influencing its call contract. Its only use in this
case would be to prevent the function from modifying a pointer that the
function itself thought it shouldn't modify. While not useless in all cases,
this compile-time checked if usually not performed in the kernel, especially
for simple functions. I'm not aware of any explicit rule regarding const usage
though.
--
Regards,
Laurent Pinchart
prev parent reply other threads:[~2014-04-01 17:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-25 4:40 [PATCH] [media] uvcvideo: Fix marking buffer erroneous in case of FID toggling Anton Leontiev
2014-03-26 17:41 ` Laurent Pinchart
2014-03-28 3:58 ` Anton Leontiev
2014-03-28 16:12 ` Laurent Pinchart
2014-03-29 5:28 ` Anton Leontiev
2014-04-01 15:24 ` Laurent Pinchart [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=10422468.Ah80osK73i@avalon \
--to=laurent.pinchart@ideasonboard.com \
--cc=bunder@t-25.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=m.chehab@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