lkml.org 
[lkml]   [2011]   [Jul]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/4] regmap: Add generic non-memory mapped register access API
At Mon, 18 Jul 2011 19:07:40 +0900,
Mark Brown wrote:
>
> +static int _regmap_raw_write(struct regmap *map, unsigned int reg,
> + const void *val, size_t val_len)
> +{
> + void *buf;
> + int ret = -ENOTSUPP;
> + size_t len;
> +
> + map->format.format_reg(map->work_buf, reg);
> +
> + /* Try to do a gather write if we can */
> + if (map->bus->gather_write)
> + ret = map->bus->gather_write(map->dev, map->work_buf,
> + map->format.reg_bytes,
> + val, val_len);
> +
> + /* Otherwise fall back on linearising by hand. */
> + if (ret == -ENOTSUPP) {
> + len = map->format.reg_bytes + val_len;
> + buf = kmalloc(len, GFP_KERNEL);
> + if (!buf)
> + return -ENOMEM;
> +
> + memcpy(buf, map->work_buf, map->format.reg_bytes);
> + memcpy(buf + map->format.reg_bytes, val, val_len);
> + ret = map->bus->write(map->dev, buf, len);
> +
> + kfree(buf);

In most cases, val = map->work_buf + map->format.reg_bytes.
How about a bit optimization?

if (ret == -ENOTSUPP) {
len = map->format.reg_bytes + val_len;
if (val == map->work_buf + map->format.reg_bytes)
ret = map->bus->write(map->dev, map->work_buf, len);
else {
buf = kmalloc(len, GFP_KERNEL);
if (!buf)
return -ENOMEM;

memcpy(buf, map->work_buf, map->format.reg_bytes);
memcpy(buf + map->format.reg_bytes, val, val_len);
ret = map->bus->write(map->dev, buf, len);

kfree(buf);
}
}


thanks,

Takashi


\
 
 \ /
  Last update: 2011-07-18 12:41    [W:0.298 / U:0.160 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site