diff options
author | Joe Perches <joe@perches.com> | 2014-05-04 20:05:04 -0400 |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2014-05-05 16:58:05 -0400 |
commit | a09c391df309c846b7c49771526acd311ccbc93e (patch) | |
tree | 8d165d673635d8293dcecff87b72bc75e6a6b740 /drivers/cdrom | |
parent | e3b6b9ef61f41d0c79f7a1341679ad4b20d7e788 (diff) |
cdrom: Remove obfuscating IOCTL_IN and IOCTL_OUT macros
Macros with hidden control flow aren't nice.
Just use copy_to/from_user directly instead.
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'drivers/cdrom')
-rw-r--r-- | drivers/cdrom/cdrom.c | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c index 8eaba535d2b2..47dee5ed5cba 100644 --- a/drivers/cdrom/cdrom.c +++ b/drivers/cdrom/cdrom.c | |||
@@ -326,15 +326,6 @@ do { \ | |||
326 | } while (0) | 326 | } while (0) |
327 | #endif | 327 | #endif |
328 | 328 | ||
329 | /* These are used to simplify getting data in from and back to user land */ | ||
330 | #define IOCTL_IN(arg, type, in) \ | ||
331 | if (copy_from_user(&(in), (type __user *) (arg), sizeof (in))) \ | ||
332 | return -EFAULT; | ||
333 | |||
334 | #define IOCTL_OUT(arg, type, out) \ | ||
335 | if (copy_to_user((type __user *) (arg), &(out), sizeof (out))) \ | ||
336 | return -EFAULT; | ||
337 | |||
338 | /* The (cdo->capability & ~cdi->mask & CDC_XXX) construct was used in | 329 | /* The (cdo->capability & ~cdi->mask & CDC_XXX) construct was used in |
339 | a lot of places. This macro makes the code more clear. */ | 330 | a lot of places. This macro makes the code more clear. */ |
340 | #define CDROM_CAN(type) (cdi->ops->capability & ~cdi->mask & (type)) | 331 | #define CDROM_CAN(type) (cdi->ops->capability & ~cdi->mask & (type)) |
@@ -2874,7 +2865,8 @@ static noinline int mmc_ioctl_cdrom_read_data(struct cdrom_device_info *cdi, | |||
2874 | blocksize = CD_FRAMESIZE_RAW0; | 2865 | blocksize = CD_FRAMESIZE_RAW0; |
2875 | break; | 2866 | break; |
2876 | } | 2867 | } |
2877 | IOCTL_IN(arg, struct cdrom_msf, msf); | 2868 | if (copy_from_user(&msf, (struct cdrom_msf __user *)arg, sizeof(msf))) |
2869 | return -EFAULT; | ||
2878 | lba = msf_to_lba(msf.cdmsf_min0, msf.cdmsf_sec0, msf.cdmsf_frame0); | 2870 | lba = msf_to_lba(msf.cdmsf_min0, msf.cdmsf_sec0, msf.cdmsf_frame0); |
2879 | /* FIXME: we need upper bound checking, too!! */ | 2871 | /* FIXME: we need upper bound checking, too!! */ |
2880 | if (lba < 0) | 2872 | if (lba < 0) |
@@ -2916,7 +2908,9 @@ static noinline int mmc_ioctl_cdrom_read_audio(struct cdrom_device_info *cdi, | |||
2916 | struct cdrom_read_audio ra; | 2908 | struct cdrom_read_audio ra; |
2917 | int lba; | 2909 | int lba; |
2918 | 2910 | ||
2919 | IOCTL_IN(arg, struct cdrom_read_audio, ra); | 2911 | if (copy_from_user(&ra, (struct cdrom_read_audio __user *)arg, |
2912 | sizeof(ra))) | ||
2913 | return -EFAULT; | ||
2920 | 2914 | ||
2921 | if (ra.addr_format == CDROM_MSF) | 2915 | if (ra.addr_format == CDROM_MSF) |
2922 | lba = msf_to_lba(ra.addr.msf.minute, | 2916 | lba = msf_to_lba(ra.addr.msf.minute, |
@@ -2940,7 +2934,8 @@ static noinline int mmc_ioctl_cdrom_subchannel(struct cdrom_device_info *cdi, | |||
2940 | int ret; | 2934 | int ret; |
2941 | struct cdrom_subchnl q; | 2935 | struct cdrom_subchnl q; |
2942 | u_char requested, back; | 2936 | u_char requested, back; |
2943 | IOCTL_IN(arg, struct cdrom_subchnl, q); | 2937 | if (copy_from_user(&q, (struct cdrom_subchnl __user *)arg, sizeof(q))) |
2938 | return -EFAULT; | ||
2944 | requested = q.cdsc_format; | 2939 | requested = q.cdsc_format; |
2945 | if (!((requested == CDROM_MSF) || | 2940 | if (!((requested == CDROM_MSF) || |
2946 | (requested == CDROM_LBA))) | 2941 | (requested == CDROM_LBA))) |
@@ -2952,7 +2947,8 @@ static noinline int mmc_ioctl_cdrom_subchannel(struct cdrom_device_info *cdi, | |||
2952 | back = q.cdsc_format; /* local copy */ | 2947 | back = q.cdsc_format; /* local copy */ |
2953 | sanitize_format(&q.cdsc_absaddr, &back, requested); | 2948 | sanitize_format(&q.cdsc_absaddr, &back, requested); |
2954 | sanitize_format(&q.cdsc_reladdr, &q.cdsc_format, requested); | 2949 | sanitize_format(&q.cdsc_reladdr, &q.cdsc_format, requested); |
2955 | IOCTL_OUT(arg, struct cdrom_subchnl, q); | 2950 | if (copy_to_user((struct cdrom_subchnl __user *)arg, &q, sizeof(q))) |
2951 | return -EFAULT; | ||
2956 | /* cd_dbg(CD_DO_IOCTL, "CDROMSUBCHNL successful\n"); */ | 2952 | /* cd_dbg(CD_DO_IOCTL, "CDROMSUBCHNL successful\n"); */ |
2957 | return 0; | 2953 | return 0; |
2958 | } | 2954 | } |
@@ -2964,7 +2960,8 @@ static noinline int mmc_ioctl_cdrom_play_msf(struct cdrom_device_info *cdi, | |||
2964 | struct cdrom_device_ops *cdo = cdi->ops; | 2960 | struct cdrom_device_ops *cdo = cdi->ops; |
2965 | struct cdrom_msf msf; | 2961 | struct cdrom_msf msf; |
2966 | cd_dbg(CD_DO_IOCTL, "entering CDROMPLAYMSF\n"); | 2962 | cd_dbg(CD_DO_IOCTL, "entering CDROMPLAYMSF\n"); |
2967 | IOCTL_IN(arg, struct cdrom_msf, msf); | 2963 | if (copy_from_user(&msf, (struct cdrom_msf __user *)arg, sizeof(msf))) |
2964 | return -EFAULT; | ||
2968 | cgc->cmd[0] = GPCMD_PLAY_AUDIO_MSF; | 2965 | cgc->cmd[0] = GPCMD_PLAY_AUDIO_MSF; |
2969 | cgc->cmd[3] = msf.cdmsf_min0; | 2966 | cgc->cmd[3] = msf.cdmsf_min0; |
2970 | cgc->cmd[4] = msf.cdmsf_sec0; | 2967 | cgc->cmd[4] = msf.cdmsf_sec0; |
@@ -2983,7 +2980,8 @@ static noinline int mmc_ioctl_cdrom_play_blk(struct cdrom_device_info *cdi, | |||
2983 | struct cdrom_device_ops *cdo = cdi->ops; | 2980 | struct cdrom_device_ops *cdo = cdi->ops; |
2984 | struct cdrom_blk blk; | 2981 | struct cdrom_blk blk; |
2985 | cd_dbg(CD_DO_IOCTL, "entering CDROMPLAYBLK\n"); | 2982 | cd_dbg(CD_DO_IOCTL, "entering CDROMPLAYBLK\n"); |
2986 | IOCTL_IN(arg, struct cdrom_blk, blk); | 2983 | if (copy_from_user(&blk, (struct cdrom_blk __user *)arg, sizeof(blk))) |
2984 | return -EFAULT; | ||
2987 | cgc->cmd[0] = GPCMD_PLAY_AUDIO_10; | 2985 | cgc->cmd[0] = GPCMD_PLAY_AUDIO_10; |
2988 | cgc->cmd[2] = (blk.from >> 24) & 0xff; | 2986 | cgc->cmd[2] = (blk.from >> 24) & 0xff; |
2989 | cgc->cmd[3] = (blk.from >> 16) & 0xff; | 2987 | cgc->cmd[3] = (blk.from >> 16) & 0xff; |
@@ -3008,7 +3006,9 @@ static noinline int mmc_ioctl_cdrom_volume(struct cdrom_device_info *cdi, | |||
3008 | 3006 | ||
3009 | cd_dbg(CD_DO_IOCTL, "entering CDROMVOLUME\n"); | 3007 | cd_dbg(CD_DO_IOCTL, "entering CDROMVOLUME\n"); |
3010 | 3008 | ||
3011 | IOCTL_IN(arg, struct cdrom_volctrl, volctrl); | 3009 | if (copy_from_user(&volctrl, (struct cdrom_volctrl __user *)arg, |
3010 | sizeof(volctrl))) | ||
3011 | return -EFAULT; | ||
3012 | 3012 | ||
3013 | cgc->buffer = buffer; | 3013 | cgc->buffer = buffer; |
3014 | cgc->buflen = 24; | 3014 | cgc->buflen = 24; |
@@ -3045,7 +3045,9 @@ static noinline int mmc_ioctl_cdrom_volume(struct cdrom_device_info *cdi, | |||
3045 | volctrl.channel1 = buffer[offset+11]; | 3045 | volctrl.channel1 = buffer[offset+11]; |
3046 | volctrl.channel2 = buffer[offset+13]; | 3046 | volctrl.channel2 = buffer[offset+13]; |
3047 | volctrl.channel3 = buffer[offset+15]; | 3047 | volctrl.channel3 = buffer[offset+15]; |
3048 | IOCTL_OUT(arg, struct cdrom_volctrl, volctrl); | 3048 | if (copy_to_user((struct cdrom_volctrl __user *)arg, &volctrl, |
3049 | sizeof(volctrl))) | ||
3050 | return -EFAULT; | ||
3049 | return 0; | 3051 | return 0; |
3050 | } | 3052 | } |
3051 | 3053 | ||
@@ -3131,11 +3133,13 @@ static noinline int mmc_ioctl_dvd_auth(struct cdrom_device_info *cdi, | |||
3131 | if (!CDROM_CAN(CDC_DVD)) | 3133 | if (!CDROM_CAN(CDC_DVD)) |
3132 | return -ENOSYS; | 3134 | return -ENOSYS; |
3133 | cd_dbg(CD_DO_IOCTL, "entering DVD_AUTH\n"); | 3135 | cd_dbg(CD_DO_IOCTL, "entering DVD_AUTH\n"); |
3134 | IOCTL_IN(arg, dvd_authinfo, ai); | 3136 | if (copy_from_user(&ai, (dvd_authinfo __user *)arg, sizeof(ai))) |
3137 | return -EFAULT; | ||
3135 | ret = dvd_do_auth(cdi, &ai); | 3138 | ret = dvd_do_auth(cdi, &ai); |
3136 | if (ret) | 3139 | if (ret) |
3137 | return ret; | 3140 | return ret; |
3138 | IOCTL_OUT(arg, dvd_authinfo, ai); | 3141 | if (copy_to_user((dvd_authinfo __user *)arg, &ai, sizeof(ai))) |
3142 | return -EFAULT; | ||
3139 | return 0; | 3143 | return 0; |
3140 | } | 3144 | } |
3141 | 3145 | ||
@@ -3148,7 +3152,8 @@ static noinline int mmc_ioctl_cdrom_next_writable(struct cdrom_device_info *cdi, | |||
3148 | ret = cdrom_get_next_writable(cdi, &next); | 3152 | ret = cdrom_get_next_writable(cdi, &next); |
3149 | if (ret) | 3153 | if (ret) |
3150 | return ret; | 3154 | return ret; |
3151 | IOCTL_OUT(arg, long, next); | 3155 | if (copy_to_user((long __user *)arg, &next, sizeof(next))) |
3156 | return -EFAULT; | ||
3152 | return 0; | 3157 | return 0; |
3153 | } | 3158 | } |
3154 | 3159 | ||
@@ -3161,7 +3166,8 @@ static noinline int mmc_ioctl_cdrom_last_written(struct cdrom_device_info *cdi, | |||
3161 | ret = cdrom_get_last_written(cdi, &last); | 3166 | ret = cdrom_get_last_written(cdi, &last); |
3162 | if (ret) | 3167 | if (ret) |
3163 | return ret; | 3168 | return ret; |
3164 | IOCTL_OUT(arg, long, last); | 3169 | if (copy_to_user((long __user *)arg, &last, sizeof(last))) |
3170 | return -EFAULT; | ||
3165 | return 0; | 3171 | return 0; |
3166 | } | 3172 | } |
3167 | 3173 | ||