Messages in this thread | | | Date | Mon, 18 Jul 2011 12:38:14 +0200 | From | Takashi Iwai <> | Subject | Re: [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
| |