Hi Ben,

On Fri, Jan 11, 2019 at 12:12 PM Ben Kao <ben....@intel.com> wrote:
>
> This patch adds driver for Omnivision's ov8856 sensor,
> the driver supports following features:
[snip]
> +static int ov8856_write_reg(struct ov8856 *ov8856, u16 reg, u16 len, u32 
> __val)
> +{
> +       struct i2c_client *client = v4l2_get_subdevdata(&ov8856->sd);
> +       unsigned int buf_i, val_i;
> +       u8 buf[6];
> +       u8 *val_p;
> +       __be32 val;
> +
> +       if (len > 4)
> +               return -EINVAL;
> +
> +       buf[0] = reg >> 8;
> +       buf[1] = reg & 0xff;

The two lines above can be simplified into one put_unaligned_be16(reg, buf);

> +
> +       val = cpu_to_be32(__val);
> +       val_p = (u8 *)&val;
> +       buf_i = 2;
> +       val_i = 4 - len;
> +
> +       while (val_i < 4)
> +               buf[buf_i++] = val_p[val_i++];

All the code above can be simplified into:

val <<= 8 * (4 - len);
put_unaligned_be32(val, buf + 2);

> +
> +       if (i2c_master_send(client, buf, len + 2) != len + 2)
> +               return -EIO;
> +
> +       return 0;
> +}

Best regards,
Tomasz

Reply via email to