Hi Andrew,
On 26.02.2016 21:59, Andrew Lunn wrote:
> Add a regmap for accessing the EEPROM, and then use that with the
> NVMEM framework. Set the NVMEM config structure to enable backward, so
> that the 'eeprom' file in sys is provided by the framework.
>
> Signed-off-by: Andrew Lunn <[email protected]>
> Acked-by: Srinivas Kandagatla <[email protected]>
> Tested-by: Bartosz Golaszewski <[email protected]>
> ---
[snip]
> +static int at24_regmap_read(void *context, const void *reg, size_t reg_size,
> + void *val, size_t val_size)
> +{
> + struct at24_data *at24 = context;
> + off_t offset = *(u32 *)reg;
> + int err;
> +
> + err = at24_read(at24, val, offset, val_size);
> + if (err)
> + return err;
> + return 0;
return at24_read(at24, val, offset, val_size);
Minus 5 LoC.
> +}
> +
> +static int at24_regmap_write(void *context, const void *data, size_t count)
> +{
> + struct at24_data *at24 = context;
> + const char *buf;
> + u32 offset;
> + size_t len;
> + int err;
> +
> + memcpy(&offset, data, sizeof(offset));
> + buf = (const char *)data + sizeof(offset);
> + len = count - sizeof(offset);
> +
> + err = at24_write(at24, buf, offset, len);
> + if (err)
> + return err;
> + return 0;
return at24_write(at24, buf, offset, len);
Minus another 5 LoC.
--
With best wishes,
Vladimir
On Wed, Mar 02, 2016 at 11:46:39PM +0200, Vladimir Zapolskiy wrote:
> Hi Andrew,
>
> On 26.02.2016 21:59, Andrew Lunn wrote:
> > Add a regmap for accessing the EEPROM, and then use that with the
> > NVMEM framework. Set the NVMEM config structure to enable backward, so
> > that the 'eeprom' file in sys is provided by the framework.
> >
> > Signed-off-by: Andrew Lunn <[email protected]>
> > Acked-by: Srinivas Kandagatla <[email protected]>
> > Tested-by: Bartosz Golaszewski <[email protected]>
> > ---
>
> [snip]
>
> > +static int at24_regmap_read(void *context, const void *reg, size_t reg_size,
> > + void *val, size_t val_size)
> > +{
> > + struct at24_data *at24 = context;
> > + off_t offset = *(u32 *)reg;
> > + int err;
> > +
> > + err = at24_read(at24, val, offset, val_size);
> > + if (err)
> > + return err;
> > + return 0;
>
> return at24_read(at24, val, offset, val_size);
>
> Minus 5 LoC.
And everything breaks :-(
regmap expects either an error code, or 0. Return a positive value and
it is not happy.
Andrew
On 02.03.2016 23:48, Andrew Lunn wrote:
> On Wed, Mar 02, 2016 at 11:46:39PM +0200, Vladimir Zapolskiy wrote:
>> Hi Andrew,
>>
>> On 26.02.2016 21:59, Andrew Lunn wrote:
>>> Add a regmap for accessing the EEPROM, and then use that with the
>>> NVMEM framework. Set the NVMEM config structure to enable backward, so
>>> that the 'eeprom' file in sys is provided by the framework.
>>>
>>> Signed-off-by: Andrew Lunn <[email protected]>
>>> Acked-by: Srinivas Kandagatla <[email protected]>
>>> Tested-by: Bartosz Golaszewski <[email protected]>
>>> ---
>>
>> [snip]
>>
>>> +static int at24_regmap_read(void *context, const void *reg, size_t reg_size,
>>> + void *val, size_t val_size)
>>> +{
>>> + struct at24_data *at24 = context;
>>> + off_t offset = *(u32 *)reg;
>>> + int err;
>>> +
>>> + err = at24_read(at24, val, offset, val_size);
>>> + if (err)
>>> + return err;
>>> + return 0;
>>
>> return at24_read(at24, val, offset, val_size);
>>
>> Minus 5 LoC.
>
> And everything breaks :-(
>
> regmap expects either an error code, or 0. Return a positive value and
> it is not happy.
>
Well, do you agree that semantically my proposed change is equal to the
original one?
Let see...
static int at24_regmap_read() {
int err;
err = at24_read(at24, val, offset, val_size);
if (err)
return err;
return 0;
}
I don't see a check for (err <= 0) returned.
--
With best wishes,
Vladimir