Hello,
I am looking at introducing some macros for i2c_msg initialization, and Ryan Mallon suggested that sometimes it could be useful to at the same time replace explicit lengths with the size of the associated buffer. But in some cases the sizes are not the same. An example is as follows, in drivers/gpu/drm/i915/dvo_ch7xxx.c:
static bool ch7xxx_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch) { struct ch7xxx_priv *ch7xxx = dvo->dev_priv; struct i2c_adapter *adapter = dvo->i2c_bus; u8 out_buf[2]; u8 in_buf[2];
struct i2c_msg msgs[] = { { .addr = dvo->slave_addr, .flags = 0, .len = 1, .buf = out_buf, }, { .addr = dvo->slave_addr, .flags = I2C_M_RD, .len = 1, .buf = in_buf, } };
out_buf[0] = addr; out_buf[1] = 0;
if (i2c_transfer(adapter, msgs, 2) == 2) { *ch = in_buf[0]; return true; };
if (!ch7xxx->quiet) { DRM_DEBUG_KMS("Unable to read register 0x%02x from %s:%02x.\n", addr, adapter->name, dvo->slave_addr); } return false; }
The buffers both have size 2, but only one byte is asked to be read or written. Is there any need for the buffers to have size 2 in this case?
Unrelatedly, is it correct that ch has type uint8_t and out_buf and in_buf have type u8?
julia
On Sat, Oct 06, 2012 at 03:20:19PM +0200, Julia Lawall wrote:
Hello,
I am looking at introducing some macros for i2c_msg initialization, and Ryan Mallon suggested that sometimes it could be useful to at the same time replace explicit lengths with the size of the associated buffer. But in some cases the sizes are not the same. An example is as follows, in drivers/gpu/drm/i915/dvo_ch7xxx.c:
static bool ch7xxx_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch) { struct ch7xxx_priv *ch7xxx = dvo->dev_priv; struct i2c_adapter *adapter = dvo->i2c_bus; u8 out_buf[2]; u8 in_buf[2];
struct i2c_msg msgs[] = { { .addr = dvo->slave_addr, .flags = 0, .len = 1, .buf = out_buf, }, { .addr = dvo->slave_addr, .flags = I2C_M_RD, .len = 1, .buf = in_buf, } }; out_buf[0] = addr; out_buf[1] = 0; if (i2c_transfer(adapter, msgs, 2) == 2) { *ch = in_buf[0]; return true; }; if (!ch7xxx->quiet) { DRM_DEBUG_KMS("Unable to read register 0x%02x from %s:%02x.\n", addr, adapter->name, dvo->slave_addr); } return false;
}
The buffers both have size 2, but only one byte is asked to be read or written. Is there any need for the buffers to have size 2 in this case?
Looks like the 2 byte buffer size is just copy&pasta from writeb. And didn't find any other reson for it not being just 1 byte.
Unrelatedly, is it correct that ch has type uint8_t and out_buf and in_buf have type u8?
drm/i915 is totally confused about the (u)int*_t vs (s|t)* types unfortunately. I think nowadays we mostly stick to _t typedefs, but not consistenly.
Yours, Daniel
dri-devel@lists.freedesktop.org