Skip to content

Commit

Permalink
[media] stk-webcam: fix an endian bug in stk_camera_read_reg()
Browse files Browse the repository at this point in the history
We pass an int pointer to stk_camera_read_reg() but only write to the
highest byte.  It's a bug on big endian systems and generally a nasty
thing to do and doesn't match the write function either.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
  • Loading branch information
Dan Carpenter authored and Mauro Carvalho Chehab committed Nov 22, 2016
1 parent 414e72c commit d08876f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions drivers/media/usb/stkwebcam/stk-sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
static int stk_sensor_outb(struct stk_camera *dev, u8 reg, u8 val)
{
int i = 0;
int tmpval = 0;
u8 tmpval = 0;

if (stk_camera_write_reg(dev, STK_IIC_TX_INDEX, reg))
return 1;
Expand All @@ -253,7 +253,7 @@ static int stk_sensor_outb(struct stk_camera *dev, u8 reg, u8 val)
static int stk_sensor_inb(struct stk_camera *dev, u8 reg, u8 *val)
{
int i = 0;
int tmpval = 0;
u8 tmpval = 0;

if (stk_camera_write_reg(dev, STK_IIC_RX_INDEX, reg))
return 1;
Expand All @@ -274,7 +274,7 @@ static int stk_sensor_inb(struct stk_camera *dev, u8 reg, u8 *val)
if (stk_camera_read_reg(dev, STK_IIC_RX_VALUE, &tmpval))
return 1;

*val = (u8) tmpval;
*val = tmpval;
return 0;
}

Expand Down
11 changes: 6 additions & 5 deletions drivers/media/usb/stkwebcam/stk-webcam.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ int stk_camera_write_reg(struct stk_camera *dev, u16 index, u8 value)
return 0;
}

int stk_camera_read_reg(struct stk_camera *dev, u16 index, int *value)
int stk_camera_read_reg(struct stk_camera *dev, u16 index, u8 *value)
{
struct usb_device *udev = dev->udev;
unsigned char *buf;
Expand All @@ -163,17 +163,18 @@ int stk_camera_read_reg(struct stk_camera *dev, u16 index, int *value)
sizeof(u8),
500);
if (ret >= 0)
memcpy(value, buf, sizeof(u8));
*value = *buf;

kfree(buf);
return ret;
}

static int stk_start_stream(struct stk_camera *dev)
{
int value;
u8 value;
int i, ret;
int value_116, value_117;
u8 value_116, value_117;


if (!is_present(dev))
return -ENODEV;
Expand Down Expand Up @@ -213,7 +214,7 @@ static int stk_start_stream(struct stk_camera *dev)

static int stk_stop_stream(struct stk_camera *dev)
{
int value;
u8 value;
int i;
if (is_present(dev)) {
stk_camera_read_reg(dev, 0x0100, &value);
Expand Down
2 changes: 1 addition & 1 deletion drivers/media/usb/stkwebcam/stk-webcam.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ struct stk_camera {
#define vdev_to_camera(d) container_of(d, struct stk_camera, vdev)

int stk_camera_write_reg(struct stk_camera *, u16, u8);
int stk_camera_read_reg(struct stk_camera *, u16, int *);
int stk_camera_read_reg(struct stk_camera *, u16, u8 *);

int stk_sensor_init(struct stk_camera *);
int stk_sensor_configure(struct stk_camera *);
Expand Down

0 comments on commit d08876f

Please sign in to comment.