From: Phillip Potter <phil@philpotter.co.uk>
To: Randy Dunlap <rdunlap@infradead.org>
Cc: rdunlap@infradead.org, axboe@kernel.dk, hch@infradead.org,
linux-kernel@vger.kernel.org, lumip@lumip.de,
linux-block@vger.kernel.org
Subject: Re: [PATCH v2] drivers/cdrom: improved ioctl for media change detection
Date: Fri, 10 Sep 2021 00:20:50 +0100 [thread overview]
Message-ID: <YTqW0ppQUAh9u4dj@equinox> (raw)
In-Reply-To: <20210909180553.8299-1-lumip@lumip.de>
On Thu, Sep 09, 2021 at 09:05:54PM +0300, Lukas Prediger wrote:
> Dear Christoph, Phillip and Randy,
>
> thanks to you all for your comments!
>
Dear Lukas,
You're welcome, thank you for the code.
> >>> Overly long line here, but more importantly this is much cleaner with
> >>> a good old if:
> >>>
> >>>
> >>> if (tmp_info.last_media_change - cdi->last_media_change_ms) < 0)
> >>> tmp_info.has_changed = 1;
> >>>
> >>
> >> Whilst I don't disagree this is technically cleaner, the existing style
> >> certainly read well to me.
>
> The if would additionally require to explicitly initialise .has_changed to
> zero for the else case, so I favored the single assignment that covers
> all cases. I don't have a strong opinion on this, though, so if the if variant
> is generally favored, I can change this. (And I will definitely fix the overlength).
>
Yes true, but I guess your existing style is harder to split across
lines in a clean way. As mentioned, I didn't mind the original code, but
the line length is a fair point. Your call on this one - those with far
more experience than me would probably argue the if/else form though.
> >> In terms of line length, checkpatch doesn't
> >> complain about it, so I guess you mean purely from a visual perspective?
> >
> > Documentation/process/coding-style.rst says:
> >
> > The preferred limit on the length of a single line is 80 columns.
> >
> > checkpatch only checks lines > 100 columns since that is OK in a few
> > cases, like a long quoted string.
> >
> > So try to limit line lengths to 80 columns unless there is some
> > other reason not to do that.
>
> I wasn't aware that checkpatch.pl does not complain if I exceed the 80 cols,
> have fixed those now for an upcoming resubmission.
>
Same, guilty as charged on this one - live and learn I guess :-)
> >>> +{
> >>> + __s64 last_media_change; /* Timestamp of the last detected media
> >>> + * change in ms. May be set by caller, updated
> >>> + * upon successful return of ioctl.
> >>> + */
> >>> + __u64 has_changed; /* Set to 1 by ioctl if last detected media
> >>>
> >>> More overly long lines. Also why is has_changed a u64 if it is used as
> >>> a boolean flag?
> >>
> >> As this is not a packed struct, would not a smaller value still take up
> >> the same space?
> >
> > Might as well be explicit about it and also make it obvious that there
> > is some space available for other fields.
>
> I had this as a __u8 in the first submission but Jens asked me to change it.
> From his feedback on this:
>
> "The struct layout should be modified such that there are no holes or
> padding in it. Probably just make the has_changed a flags thing, and
> make it u64 as well. Then you can define bit 0 to be HAS_CHANGED, and
> that leaves you room to add more flags in the future."
> https://lore.kernel.org/lkml/6d6c533d-465e-33ee-5801-cb7ea84924a8@kernel.dk/
>
Yeah, maybe just a bit more in the comment to emphasize the room for
extra bits in has_changed? I agree it looks fine like this to me though
given the lack of struck packing anyway.
> I changed it to __u64 to address this. We could think about turning it
> back to a __u8 (or bool) and add some explicit padding members
> (a __u8 reserved[3]?), but honestly I don't see much real benefit in that
> compared to how it is now.
>
I agree with you on this personally, I think it's fine.
Regards,
Phil
next prev parent reply other threads:[~2021-09-09 23:20 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-29 14:37 [PATCH v2] drivers/cdrom: improved ioctl for media change detection Lukas Prediger
2021-09-06 20:11 ` Jens Axboe
2021-09-06 22:57 ` Phillip Potter
2021-09-08 23:51 ` Phillip Potter
2021-09-09 18:04 ` Lukas Prediger
2021-09-09 23:07 ` Phillip Potter
2021-09-07 6:35 ` Christoph Hellwig
2021-09-09 0:17 ` Phillip Potter
2021-09-09 0:42 ` Randy Dunlap
2021-09-09 18:05 ` Lukas Prediger
2021-09-09 23:20 ` Phillip Potter [this message]
2021-09-10 1:25 ` Randy Dunlap
2021-09-10 7:59 ` Phillip Potter
2021-09-09 23:00 ` Phillip Potter
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=YTqW0ppQUAh9u4dj@equinox \
--to=phil@philpotter.co.uk \
--cc=axboe@kernel.dk \
--cc=hch@infradead.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lumip@lumip.de \
--cc=rdunlap@infradead.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