Commit 52ea1619 authored by Eric Sesterhenn / snakebyte's avatar Eric Sesterhenn / snakebyte Committed by Greg Kroah-Hartman

[PATCH] USB: Remove LINUX_VERSION_CODE check in pwc/pwc-ctrl.c

this patch removes compatibility with 2.4 kernel, which makes
the code much easier to read.
Signed-off-by: default avatarEric Sesterhenn <snakebyte@gmx.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 97906369
...@@ -1152,45 +1152,6 @@ int pwc_get_cmos_sensor(struct pwc_device *pdev, int *sensor) ...@@ -1152,45 +1152,6 @@ int pwc_get_cmos_sensor(struct pwc_device *pdev, int *sensor)
/* End of Add-Ons */ /* End of Add-Ons */
/* ************************************************* */ /* ************************************************* */
/* Linux 2.5.something and 2.6 pass direct pointers to arguments of
ioctl() calls. With 2.4, you have to do tedious copy_from_user()
and copy_to_user() calls. With these macros we circumvent this,
and let me maintain only one source file. The functionality is
exactly the same otherwise.
*/
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
/* define local variable for arg */
#define ARG_DEF(ARG_type, ARG_name)\
ARG_type *ARG_name = arg;
/* copy arg to local variable */
#define ARG_IN(ARG_name) /* nothing */
/* argument itself (referenced) */
#define ARGR(ARG_name) (*ARG_name)
/* argument address */
#define ARGA(ARG_name) ARG_name
/* copy local variable to arg */
#define ARG_OUT(ARG_name) /* nothing */
#else
#define ARG_DEF(ARG_type, ARG_name)\
ARG_type ARG_name;
#define ARG_IN(ARG_name)\
if (copy_from_user(&ARG_name, arg, sizeof(ARG_name))) {\
ret = -EFAULT;\
break;\
}
#define ARGR(ARG_name) ARG_name
#define ARGA(ARG_name) &ARG_name
#define ARG_OUT(ARG_name)\
if (copy_to_user(arg, &ARG_name, sizeof(ARG_name))) {\
ret = -EFAULT;\
break;\
}
#endif
int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg) int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
{ {
...@@ -1220,243 +1181,206 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg) ...@@ -1220,243 +1181,206 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
case VIDIOCPWCSCQUAL: case VIDIOCPWCSCQUAL:
{ {
ARG_DEF(int, qual) int *qual = arg;
ARG_IN(qual) if (*qual < 0 || *qual > 3)
if (ARGR(qual) < 0 || ARGR(qual) > 3)
ret = -EINVAL; ret = -EINVAL;
else else
ret = pwc_try_video_mode(pdev, pdev->view.x, pdev->view.y, pdev->vframes, ARGR(qual), pdev->vsnapshot); ret = pwc_try_video_mode(pdev, pdev->view.x, pdev->view.y, pdev->vframes, *qual, pdev->vsnapshot);
if (ret >= 0) if (ret >= 0)
pdev->vcompression = ARGR(qual); pdev->vcompression = *qual;
break; break;
} }
case VIDIOCPWCGCQUAL: case VIDIOCPWCGCQUAL:
{ {
ARG_DEF(int, qual) int *qual = arg;
*qual = pdev->vcompression;
ARGR(qual) = pdev->vcompression;
ARG_OUT(qual)
break; break;
} }
case VIDIOCPWCPROBE: case VIDIOCPWCPROBE:
{ {
ARG_DEF(struct pwc_probe, probe) struct pwc_probe *probe = arg;
strcpy(probe->name, pdev->vdev->name);
strcpy(ARGR(probe).name, pdev->vdev->name); probe->type = pdev->type;
ARGR(probe).type = pdev->type;
ARG_OUT(probe)
break; break;
} }
case VIDIOCPWCGSERIAL: case VIDIOCPWCGSERIAL:
{ {
ARG_DEF(struct pwc_serial, serial) struct pwc_serial *serial = arg;
strcpy(serial->serial, pdev->serial);
strcpy(ARGR(serial).serial, pdev->serial);
ARG_OUT(serial)
break; break;
} }
case VIDIOCPWCSAGC: case VIDIOCPWCSAGC:
{ {
ARG_DEF(int, agc) int *agc = arg;
if (pwc_set_agc(pdev, *agc < 0 ? 1 : 0, *agc))
ARG_IN(agc)
if (pwc_set_agc(pdev, ARGR(agc) < 0 ? 1 : 0, ARGR(agc)))
ret = -EINVAL; ret = -EINVAL;
break; break;
} }
case VIDIOCPWCGAGC: case VIDIOCPWCGAGC:
{ {
ARG_DEF(int, agc) int *agc = arg;
if (pwc_get_agc(pdev, ARGA(agc))) if (pwc_get_agc(pdev, agc))
ret = -EINVAL; ret = -EINVAL;
ARG_OUT(agc)
break; break;
} }
case VIDIOCPWCSSHUTTER: case VIDIOCPWCSSHUTTER:
{ {
ARG_DEF(int, shutter_speed) int *shutter_speed = arg;
ret = pwc_set_shutter_speed(pdev, *shutter_speed < 0 ? 1 : 0, *shutter_speed);
ARG_IN(shutter_speed)
ret = pwc_set_shutter_speed(pdev, ARGR(shutter_speed) < 0 ? 1 : 0, ARGR(shutter_speed));
break; break;
} }
case VIDIOCPWCSAWB: case VIDIOCPWCSAWB:
{ {
ARG_DEF(struct pwc_whitebalance, wb) struct pwc_whitebalance *wb = arg;
ARG_IN(wb) ret = pwc_set_awb(pdev, wb->mode);
ret = pwc_set_awb(pdev, ARGR(wb).mode); if (ret >= 0 && wb->mode == PWC_WB_MANUAL) {
if (ret >= 0 && ARGR(wb).mode == PWC_WB_MANUAL) { pwc_set_red_gain(pdev, wb->manual_red);
pwc_set_red_gain(pdev, ARGR(wb).manual_red); pwc_set_blue_gain(pdev, wb->manual_blue);
pwc_set_blue_gain(pdev, ARGR(wb).manual_blue);
} }
break; break;
} }
case VIDIOCPWCGAWB: case VIDIOCPWCGAWB:
{ {
ARG_DEF(struct pwc_whitebalance, wb) struct pwc_whitebalance *wb = arg;
memset(ARGA(wb), 0, sizeof(struct pwc_whitebalance)); memset(wb, 0, sizeof(struct pwc_whitebalance));
ARGR(wb).mode = pwc_get_awb(pdev); wb->mode = pwc_get_awb(pdev);
if (ARGR(wb).mode < 0) if (wb->mode < 0)
ret = -EINVAL; ret = -EINVAL;
else { else {
if (ARGR(wb).mode == PWC_WB_MANUAL) { if (wb->mode == PWC_WB_MANUAL) {
ret = pwc_get_red_gain(pdev, &ARGR(wb).manual_red); ret = pwc_get_red_gain(pdev, &wb->manual_red);
if (ret < 0) if (ret < 0)
break; break;
ret = pwc_get_blue_gain(pdev, &ARGR(wb).manual_blue); ret = pwc_get_blue_gain(pdev, &wb->manual_blue);
if (ret < 0) if (ret < 0)
break; break;
} }
if (ARGR(wb).mode == PWC_WB_AUTO) { if (wb->mode == PWC_WB_AUTO) {
ret = pwc_read_red_gain(pdev, &ARGR(wb).read_red); ret = pwc_read_red_gain(pdev, &wb->read_red);
if (ret < 0) if (ret < 0)
break; break;
ret =pwc_read_blue_gain(pdev, &ARGR(wb).read_blue); ret = pwc_read_blue_gain(pdev, &wb->read_blue);
if (ret < 0) if (ret < 0)
break; break;
} }
} }
ARG_OUT(wb)
break; break;
} }
case VIDIOCPWCSAWBSPEED: case VIDIOCPWCSAWBSPEED:
{ {
ARG_DEF(struct pwc_wb_speed, wbs) struct pwc_wb_speed *wbs = arg;
if (ARGR(wbs).control_speed > 0) { if (wbs->control_speed > 0) {
ret = pwc_set_wb_speed(pdev, ARGR(wbs).control_speed); ret = pwc_set_wb_speed(pdev, wbs->control_speed);
} }
if (ARGR(wbs).control_delay > 0) { if (wbs->control_delay > 0) {
ret = pwc_set_wb_delay(pdev, ARGR(wbs).control_delay); ret = pwc_set_wb_delay(pdev, wbs->control_delay);
} }
break; break;
} }
case VIDIOCPWCGAWBSPEED: case VIDIOCPWCGAWBSPEED:
{ {
ARG_DEF(struct pwc_wb_speed, wbs) struct pwc_wb_speed *wbs = arg;
ret = pwc_get_wb_speed(pdev, &ARGR(wbs).control_speed); ret = pwc_get_wb_speed(pdev, &wbs->control_speed);
if (ret < 0) if (ret < 0)
break; break;
ret = pwc_get_wb_delay(pdev, &ARGR(wbs).control_delay); ret = pwc_get_wb_delay(pdev, &wbs->control_delay);
if (ret < 0) if (ret < 0)
break; break;
ARG_OUT(wbs)
break; break;
} }
case VIDIOCPWCSLED: case VIDIOCPWCSLED:
{ {
ARG_DEF(struct pwc_leds, leds) struct pwc_leds *leds = arg;
ret = pwc_set_leds(pdev, leds->led_on, leds->led_off);
ARG_IN(leds)
ret = pwc_set_leds(pdev, ARGR(leds).led_on, ARGR(leds).led_off);
break; break;
} }
case VIDIOCPWCGLED: case VIDIOCPWCGLED:
{ {
ARG_DEF(struct pwc_leds, leds) struct pwc_leds *leds = arg;
ret = pwc_get_leds(pdev, &leds->led_on, &leds->led_off);
ret = pwc_get_leds(pdev, &ARGR(leds).led_on, &ARGR(leds).led_off);
ARG_OUT(leds)
break; break;
} }
case VIDIOCPWCSCONTOUR: case VIDIOCPWCSCONTOUR:
{ {
ARG_DEF(int, contour) int *contour = arg;
ret = pwc_set_contour(pdev, *contour);
ARG_IN(contour)
ret = pwc_set_contour(pdev, ARGR(contour));
break; break;
} }
case VIDIOCPWCGCONTOUR: case VIDIOCPWCGCONTOUR:
{ {
ARG_DEF(int, contour) int *contour = arg;
ret = pwc_get_contour(pdev, contour);
ret = pwc_get_contour(pdev, ARGA(contour));
ARG_OUT(contour)
break; break;
} }
case VIDIOCPWCSBACKLIGHT: case VIDIOCPWCSBACKLIGHT:
{ {
ARG_DEF(int, backlight) int *backlight = arg;
ret = pwc_set_backlight(pdev, *backlight);
ARG_IN(backlight)
ret = pwc_set_backlight(pdev, ARGR(backlight));
break; break;
} }
case VIDIOCPWCGBACKLIGHT: case VIDIOCPWCGBACKLIGHT:
{ {
ARG_DEF(int, backlight) int *backlight = arg;
ret = pwc_get_backlight(pdev, backlight);
ret = pwc_get_backlight(pdev, ARGA(backlight));
ARG_OUT(backlight)
break; break;
} }
case VIDIOCPWCSFLICKER: case VIDIOCPWCSFLICKER:
{ {
ARG_DEF(int, flicker) int *flicker = arg;
ret = pwc_set_flicker(pdev, *flicker);
ARG_IN(flicker)
ret = pwc_set_flicker(pdev, ARGR(flicker));
break; break;
} }
case VIDIOCPWCGFLICKER: case VIDIOCPWCGFLICKER:
{ {
ARG_DEF(int, flicker) int *flicker = arg;
ret = pwc_get_flicker(pdev, flicker);
ret = pwc_get_flicker(pdev, ARGA(flicker));
ARG_OUT(flicker)
break; break;
} }
case VIDIOCPWCSDYNNOISE: case VIDIOCPWCSDYNNOISE:
{ {
ARG_DEF(int, dynnoise) int *dynnoise = arg;
ret = pwc_set_dynamic_noise(pdev, *dynnoise);
ARG_IN(dynnoise)
ret = pwc_set_dynamic_noise(pdev, ARGR(dynnoise));
break; break;
} }
case VIDIOCPWCGDYNNOISE: case VIDIOCPWCGDYNNOISE:
{ {
ARG_DEF(int, dynnoise) int *dynnoise = arg;
ret = pwc_get_dynamic_noise(pdev, dynnoise);
ret = pwc_get_dynamic_noise(pdev, ARGA(dynnoise));
ARG_OUT(dynnoise);
break; break;
} }
case VIDIOCPWCGREALSIZE: case VIDIOCPWCGREALSIZE:
{ {
ARG_DEF(struct pwc_imagesize, size) struct pwc_imagesize *size = arg;
size->width = pdev->image.x;
ARGR(size).width = pdev->image.x; size->height = pdev->image.y;
ARGR(size).height = pdev->image.y;
ARG_OUT(size)
break; break;
} }
...@@ -1464,10 +1388,9 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg) ...@@ -1464,10 +1388,9 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
{ {
if (pdev->features & FEATURE_MOTOR_PANTILT) if (pdev->features & FEATURE_MOTOR_PANTILT)
{ {
ARG_DEF(int, flags) int *flags = arg;
ARG_IN(flags) ret = pwc_mpt_reset(pdev, *flags);
ret = pwc_mpt_reset(pdev, ARGR(flags));
if (ret >= 0) if (ret >= 0)
{ {
pdev->pan_angle = 0; pdev->pan_angle = 0;
...@@ -1485,10 +1408,8 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg) ...@@ -1485,10 +1408,8 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
{ {
if (pdev->features & FEATURE_MOTOR_PANTILT) if (pdev->features & FEATURE_MOTOR_PANTILT)
{ {
ARG_DEF(struct pwc_mpt_range, range) struct pwc_mpt_range *range = arg;
*range = pdev->angle_range;
ARGR(range) = pdev->angle_range;
ARG_OUT(range)
} }
else else
{ {
...@@ -1503,21 +1424,19 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg) ...@@ -1503,21 +1424,19 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
if (pdev->features & FEATURE_MOTOR_PANTILT) if (pdev->features & FEATURE_MOTOR_PANTILT)
{ {
ARG_DEF(struct pwc_mpt_angles, angles) struct pwc_mpt_angles *angles = arg;
ARG_IN(angles)
/* The camera can only set relative angles, so /* The camera can only set relative angles, so
do some calculations when getting an absolute angle . do some calculations when getting an absolute angle .
*/ */
if (ARGR(angles).absolute) if (angles->absolute)
{ {
new_pan = ARGR(angles).pan; new_pan = angles->pan;
new_tilt = ARGR(angles).tilt; new_tilt = angles->tilt;
} }
else else
{ {
new_pan = pdev->pan_angle + ARGR(angles).pan; new_pan = pdev->pan_angle + angles->pan;
new_tilt = pdev->tilt_angle + ARGR(angles).tilt; new_tilt = pdev->tilt_angle + angles->tilt;
} }
/* check absolute ranges */ /* check absolute ranges */
if (new_pan < pdev->angle_range.pan_min || if (new_pan < pdev->angle_range.pan_min ||
...@@ -1560,12 +1479,11 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg) ...@@ -1560,12 +1479,11 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
if (pdev->features & FEATURE_MOTOR_PANTILT) if (pdev->features & FEATURE_MOTOR_PANTILT)
{ {
ARG_DEF(struct pwc_mpt_angles, angles) struct pwc_mpt_angles *angles = arg;
ARGR(angles).absolute = 1; angles->absolute = 1;
ARGR(angles).pan = pdev->pan_angle; angles->pan = pdev->pan_angle;
ARGR(angles).tilt = pdev->tilt_angle; angles->tilt = pdev->tilt_angle;
ARG_OUT(angles)
} }
else else
{ {
...@@ -1578,10 +1496,8 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg) ...@@ -1578,10 +1496,8 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
{ {
if (pdev->features & FEATURE_MOTOR_PANTILT) if (pdev->features & FEATURE_MOTOR_PANTILT)
{ {
ARG_DEF(struct pwc_mpt_status, status) struct pwc_mpt_status *status = arg;
ret = pwc_mpt_get_status(pdev, status);
ret = pwc_mpt_get_status(pdev, ARGA(status));
ARG_OUT(status)
} }
else else
{ {
...@@ -1592,24 +1508,22 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg) ...@@ -1592,24 +1508,22 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
case VIDIOCPWCGVIDCMD: case VIDIOCPWCGVIDCMD:
{ {
ARG_DEF(struct pwc_video_command, cmd); struct pwc_video_command *cmd = arg;
ARGR(cmd).type = pdev->type; cmd->type = pdev->type;
ARGR(cmd).release = pdev->release; cmd->release = pdev->release;
ARGR(cmd).command_len = pdev->cmd_len; cmd->command_len = pdev->cmd_len;
memcpy(&ARGR(cmd).command_buf, pdev->cmd_buf, pdev->cmd_len); memcpy(&cmd->command_buf, pdev->cmd_buf, pdev->cmd_len);
ARGR(cmd).bandlength = pdev->vbandlength; cmd->bandlength = pdev->vbandlength;
ARGR(cmd).frame_size = pdev->frame_size; cmd->frame_size = pdev->frame_size;
ARG_OUT(cmd)
break; break;
} }
/* /*
case VIDIOCPWCGVIDTABLE: case VIDIOCPWCGVIDTABLE:
{ {
ARG_DEF(struct pwc_table_init_buffer, table); struct pwc_table_init_buffer *table = arg;
ARGR(table).len = pdev->cmd_len; table->len = pdev->cmd_len;
memcpy(&ARGR(table).buffer, pdev->decompress_data, pdev->decompressor->table_size); memcpy(&table->buffer, pdev->decompress_data, pdev->decompressor->table_size);
ARG_OUT(table)
break; break;
} }
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment