linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Lukas Prediger <lumip@lumip.de>
Cc: axboe@kernel.dk, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] drivers/cdrom: improved ioctl for media change detection
Date: Tue, 7 Sep 2021 07:35:25 +0100	[thread overview]
Message-ID: <YTcILRYw/AKen0X4@infradead.org> (raw)
In-Reply-To: <20210829143735.512146-1-lumip@lumip.de>

> +static int cdrom_ioctl_timed_media_change(struct cdrom_device_info *cdi,
> +		unsigned long arg)
> +{
> +	int ret;
> +	struct cdrom_timed_media_change_info __user *info;
> +	struct cdrom_timed_media_change_info tmp_info;
> +
> +	if (!CDROM_CAN(CDC_MEDIA_CHANGED))
> +		return -ENOSYS;
> +
> +	info = (struct cdrom_timed_media_change_info __user *)arg;
> +	cd_dbg(CD_DO_IOCTL, "entering CDROM_TIMED_MEDIA_CHANGE\n");
> +
> +	ret = cdrom_ioctl_media_changed(cdi, CDSL_CURRENT);
> +	if (ret < 0)
> +		return ret;
> +
> +	if (copy_from_user(&tmp_info, info, sizeof(tmp_info)) != 0)
> +		return -EFAULT;
> +
> +	tmp_info.has_changed = ((tmp_info.last_media_change - cdi->last_media_change_ms) < 0);

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;

> +{
> +	__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?

  parent reply	other threads:[~2021-09-07  6:37 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 [this message]
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
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=YTcILRYw/AKen0X4@infradead.org \
    --to=hch@infradead.org \
    --cc=axboe@kernel.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lumip@lumip.de \
    /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).