diff mbox series

[3/7] cdrom: factor out a cdrom_read_tocentry helper

Message ID 20200423071224.500849-4-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [1/7] block: add a cdrom_device_info pointer to struct gendisk | expand

Commit Message

Christoph Hellwig April 23, 2020, 7:12 a.m. UTC
Factor out a version of the CDROMREADTOCENTRY ioctl handler that can
be called directly from kernel space.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/cdrom/cdrom.c | 39 ++++++++++++++++++++++-----------------
 include/linux/cdrom.h |  3 +++
 2 files changed, 25 insertions(+), 17 deletions(-)

Comments

Damien Le Moal April 23, 2020, 7:41 a.m. UTC | #1
On 2020/04/23 16:15, Christoph Hellwig wrote:
> Factor out a version of the CDROMREADTOCENTRY ioctl handler that can
> be called directly from kernel space.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  drivers/cdrom/cdrom.c | 39 ++++++++++++++++++++++-----------------
>  include/linux/cdrom.h |  3 +++
>  2 files changed, 25 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
> index a1d2112fd283..c91d1e138214 100644
> --- a/drivers/cdrom/cdrom.c
> +++ b/drivers/cdrom/cdrom.c
> @@ -2666,32 +2666,37 @@ static int cdrom_ioctl_read_tochdr(struct cdrom_device_info *cdi,
>  	return 0;
>  }
>  
> +int cdrom_read_tocentry(struct cdrom_device_info *cdi,
> +		struct cdrom_tocentry *entry)
> +{
> +	u8 requested_format = entry->cdte_format;
> +	int ret;
> +
> +	if (requested_format != CDROM_MSF && requested_format != CDROM_LBA)
> +		return -EINVAL;
> +
> +	/* make interface to low-level uniform */
> +	entry->cdte_format = CDROM_MSF;
> +	ret = cdi->ops->audio_ioctl(cdi, CDROMREADTOCENTRY, entry);
> +	if (!ret)
> +		sanitize_format(&entry->cdte_addr, &entry->cdte_format,
> +				requested_format);
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(cdrom_read_tocentry);
> +
>  static int cdrom_ioctl_read_tocentry(struct cdrom_device_info *cdi,
>  		void __user *argp)
>  {
>  	struct cdrom_tocentry entry;
> -	u8 requested_format;
>  	int ret;
>  
> -	/* cd_dbg(CD_DO_IOCTL, "entering CDROMREADTOCENTRY\n"); */
> -
>  	if (copy_from_user(&entry, argp, sizeof(entry)))
>  		return -EFAULT;
> -
> -	requested_format = entry.cdte_format;
> -	if (requested_format != CDROM_MSF && requested_format != CDROM_LBA)
> -		return -EINVAL;
> -	/* make interface to low-level uniform */
> -	entry.cdte_format = CDROM_MSF;
> -	ret = cdi->ops->audio_ioctl(cdi, CDROMREADTOCENTRY, &entry);
> -	if (ret)
> -		return ret;
> -	sanitize_format(&entry.cdte_addr, &entry.cdte_format, requested_format);
> -
> -	if (copy_to_user(argp, &entry, sizeof(entry)))
> +	ret = cdrom_read_tocentry(cdi, &entry);
> +	if (!ret && copy_to_user(argp, &entry, sizeof(entry)))
>  		return -EFAULT;
> -	/* cd_dbg(CD_DO_IOCTL, "CDROMREADTOCENTRY successful\n"); */
> -	return 0;
> +	return ret;
>  }
>  
>  static int cdrom_ioctl_play_msf(struct cdrom_device_info *cdi,
> diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
> index 4f74ce050253..008c4d79fa33 100644
> --- a/include/linux/cdrom.h
> +++ b/include/linux/cdrom.h
> @@ -94,6 +94,9 @@ struct cdrom_device_ops {
>  			       struct packet_command *);
>  };
>  
> +int cdrom_read_tocentry(struct cdrom_device_info *cdi,
> +		struct cdrom_tocentry *entry);
> +
>  /* the general block_device operations structure: */
>  extern int cdrom_open(struct cdrom_device_info *cdi, struct block_device *bdev,
>  			fmode_t mode);
> 

Looks OK to me.

Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
diff mbox series

Patch

diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index a1d2112fd283..c91d1e138214 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -2666,32 +2666,37 @@  static int cdrom_ioctl_read_tochdr(struct cdrom_device_info *cdi,
 	return 0;
 }
 
+int cdrom_read_tocentry(struct cdrom_device_info *cdi,
+		struct cdrom_tocentry *entry)
+{
+	u8 requested_format = entry->cdte_format;
+	int ret;
+
+	if (requested_format != CDROM_MSF && requested_format != CDROM_LBA)
+		return -EINVAL;
+
+	/* make interface to low-level uniform */
+	entry->cdte_format = CDROM_MSF;
+	ret = cdi->ops->audio_ioctl(cdi, CDROMREADTOCENTRY, entry);
+	if (!ret)
+		sanitize_format(&entry->cdte_addr, &entry->cdte_format,
+				requested_format);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(cdrom_read_tocentry);
+
 static int cdrom_ioctl_read_tocentry(struct cdrom_device_info *cdi,
 		void __user *argp)
 {
 	struct cdrom_tocentry entry;
-	u8 requested_format;
 	int ret;
 
-	/* cd_dbg(CD_DO_IOCTL, "entering CDROMREADTOCENTRY\n"); */
-
 	if (copy_from_user(&entry, argp, sizeof(entry)))
 		return -EFAULT;
-
-	requested_format = entry.cdte_format;
-	if (requested_format != CDROM_MSF && requested_format != CDROM_LBA)
-		return -EINVAL;
-	/* make interface to low-level uniform */
-	entry.cdte_format = CDROM_MSF;
-	ret = cdi->ops->audio_ioctl(cdi, CDROMREADTOCENTRY, &entry);
-	if (ret)
-		return ret;
-	sanitize_format(&entry.cdte_addr, &entry.cdte_format, requested_format);
-
-	if (copy_to_user(argp, &entry, sizeof(entry)))
+	ret = cdrom_read_tocentry(cdi, &entry);
+	if (!ret && copy_to_user(argp, &entry, sizeof(entry)))
 		return -EFAULT;
-	/* cd_dbg(CD_DO_IOCTL, "CDROMREADTOCENTRY successful\n"); */
-	return 0;
+	return ret;
 }
 
 static int cdrom_ioctl_play_msf(struct cdrom_device_info *cdi,
diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
index 4f74ce050253..008c4d79fa33 100644
--- a/include/linux/cdrom.h
+++ b/include/linux/cdrom.h
@@ -94,6 +94,9 @@  struct cdrom_device_ops {
 			       struct packet_command *);
 };
 
+int cdrom_read_tocentry(struct cdrom_device_info *cdi,
+		struct cdrom_tocentry *entry);
+
 /* the general block_device operations structure: */
 extern int cdrom_open(struct cdrom_device_info *cdi, struct block_device *bdev,
 			fmode_t mode);