From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756240Ab1GRKiX (ORCPT ); Mon, 18 Jul 2011 06:38:23 -0400 Received: from cantor2.suse.de ([195.135.220.15]:60913 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750948Ab1GRKiW (ORCPT ); Mon, 18 Jul 2011 06:38:22 -0400 Date: Mon, 18 Jul 2011 12:38:14 +0200 Message-ID: From: Takashi Iwai To: Mark Brown Cc: Greg KH , Grant Likely , Jean Delvare , Ben Dooks , Dimitris Papastamos , Liam Girdwood , Samuel Oritz , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/4] regmap: Add generic non-memory mapped register access API In-Reply-To: <1310983663-6404-1-git-send-email-broonie@opensource.wolfsonmicro.com> References: <20110718100444.GD423@opensource.wolfsonmicro.com> <1310983663-6404-1-git-send-email-broonie@opensource.wolfsonmicro.com> User-Agent: Wanderlust/2.15.6 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.7 Emacs/23.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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