[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <s5hsjq3kh61.wl%tiwai@suse.de>
Date: Mon, 18 Jul 2011 12:38:14 +0200
From: Takashi Iwai <tiwai@...e.de>
To: Mark Brown <broonie@...nsource.wolfsonmicro.com>
Cc: Greg KH <greg@...ah.com>, Grant Likely <grant@...retlab.ca>,
Jean Delvare <khali@...ux-fr.org>,
Ben Dooks <ben-linux@...ff.org>,
Dimitris Papastamos <dp@...nsource.wolfsonmicro.com>,
Liam Girdwood <lrg@...com>,
Samuel Oritz <sameo@...ux.intel.com>,
linux-kernel@...r.kernel.org
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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists