Received: by 10.223.185.116 with SMTP id b49csp1891196wrg; Thu, 22 Feb 2018 05:00:33 -0800 (PST) X-Google-Smtp-Source: AH8x225d03aZ2qGWCF7P3JkKYbJKs31u1GoY6zjak0qH5fQxRhOBdtraP/pGC/JAAUZaf1zENJwW X-Received: by 2002:a17:902:b090:: with SMTP id p16-v6mr6643482plr.324.1519304433867; Thu, 22 Feb 2018 05:00:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519304433; cv=none; d=google.com; s=arc-20160816; b=Lp53SiL4SqmiFuD1e13uBaU9LiNlfNBKt4qk8YF4dZZ2+6q8Q0tjF8CWwX0avAvODp FnDTpo4fEPaDjlRFLF2wh5OAzK0Qy59VUP2RejsyI/il3jfBkLVv+iVfC/bJi+19l+NW 3vcCzit/DXr+en+h6RpqRQgN8Dk0xJhMPMcbKR0jHujrzfNFCL7bRR3AgzcgkXxBdrJf y0lODtSy1yhEKfx4Dcf9/l+HpgoZal6sjpINjqQQYr+e8EdEUJ8y7DJTkCDmgDlDjlW5 SpOmsWqo0qoaED09Mz4qHyS+BMOFZyhgjRxe+4d3ltQ+eXNz/lHmO7IWJnZQDIWLakqZ Zqyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=88AZNFjJP8KGXj7oC1RYTtoNWTncTmFRpaeWsOJJbD4=; b=WZxDvwjyO7GSFEr+ixNApGkvTn5Sw6hLRvJoulEqbUI/taujSsplyoMoSsrzMNVLXf bNwUigoc5bvjAXee3Y42FrC35E+59hp9JYZWkAC958skCQrYZqOdscOzYzr7U9tKfnw5 u5FK0KKbcjAyrrJGZ4UlG0gYJgCHLQXlxCjQ81TMftwmMYceeZcwawvVT83DZ36ZlDFd 6909daaTLN6muq74/MMsf3GR+u8/umSACCjQRKeahJrRrQn1cWV64mhfA0js9N9zyOsC I2fr/4VUBh2mzxx155456s8qdTHEM7cEZofpf0Vxb7nrhkeMDWZXWkZWnV+vj7iZ9Cg7 VEfg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t14-v6si19538plm.20.2018.02.22.05.00.18; Thu, 22 Feb 2018 05:00:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932442AbeBVM7W (ORCPT + 99 others); Thu, 22 Feb 2018 07:59:22 -0500 Received: from mx0a-001ae601.pphosted.com ([67.231.149.25]:60838 "EHLO mx0b-001ae601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753816AbeBVM7R (ORCPT ); Thu, 22 Feb 2018 07:59:17 -0500 Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w1MCsREO021818; Thu, 22 Feb 2018 06:59:15 -0600 Authentication-Results: ppops.net; spf=none smtp.mailfrom=ckeepax@opensource.cirrus.com Received: from mail4.cirrus.com ([87.246.98.35]) by mx0a-001ae601.pphosted.com with ESMTP id 2g6jp5enpj-1; Thu, 22 Feb 2018 06:59:15 -0600 Received: from EX17.ad.cirrus.com (unknown [172.20.9.81]) by mail4.cirrus.com (Postfix) with ESMTP id 4D0E0611CE6F; Thu, 22 Feb 2018 07:00:08 -0600 (CST) Received: from imbe.wolfsonmicro.main (198.61.95.81) by EX17.ad.cirrus.com (172.20.9.81) with Microsoft SMTP Server id 14.3.301.0; Thu, 22 Feb 2018 12:59:14 +0000 Received: from algalon.ad.cirrus.com (algalon.ad.cirrus.com [198.90.251.122]) by imbe.wolfsonmicro.main (8.14.4/8.14.4) with ESMTP id w1MCxEPq011915; Thu, 22 Feb 2018 12:59:14 GMT From: Charles Keepax To: CC: , Subject: [PATCH 4/5] regmap: Tidy up regmap_raw_write chunking code Date: Thu, 22 Feb 2018 12:59:13 +0000 Message-ID: <20180222125914.17016-4-ckeepax@opensource.cirrus.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180222125914.17016-1-ckeepax@opensource.cirrus.com> References: <20180222125914.17016-1-ckeepax@opensource.cirrus.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=836 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1802220164 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Raw writes may need to be split into small chunks if max_raw_write is set. Tidy up the code implementing this, the new code is slightly clearer, slightly shorter and slightly more efficient. Signed-off-by: Charles Keepax --- drivers/base/regmap/regmap.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index dd17e2e7a3d7..6809b33d6ab1 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -1814,40 +1814,35 @@ int _regmap_raw_write(struct regmap *map, unsigned int reg, { size_t val_bytes = map->format.val_bytes; size_t val_count = val_len / val_bytes; - int chunk_stride = map->reg_stride; - size_t chunk_size = val_bytes; - size_t chunk_count = val_count; + size_t chunk_count, chunk_bytes; + size_t chunk_regs = val_count; int ret, i; if (!val_count) return -EINVAL; - if (!map->use_single_write) { - if (map->max_raw_write) - chunk_size = map->max_raw_write; - else - chunk_size = val_len; - if (chunk_size % val_bytes) - chunk_size -= chunk_size % val_bytes; - chunk_count = val_len / chunk_size; - chunk_stride *= chunk_size / val_bytes; - } + if (map->use_single_write) + chunk_regs = 1; + else if (map->max_raw_write && val_len > map->max_raw_write) + chunk_regs = map->max_raw_write / val_bytes; + + chunk_count = val_count / chunk_regs; + chunk_bytes = chunk_regs * val_bytes; /* Write as many bytes as possible with chunk_size */ for (i = 0; i < chunk_count; i++) { - ret = _regmap_raw_write_impl(map, - reg + (i * chunk_stride), - val + (i * chunk_size), - chunk_size); + ret = _regmap_raw_write_impl(map, reg, val, chunk_bytes); if (ret) return ret; + + reg += regmap_get_offset(map, chunk_regs); + val += chunk_bytes; + val_len -= chunk_bytes; } /* Write remaining bytes */ - if (!ret && chunk_size * i < val_len) - ret = _regmap_raw_write_impl(map, reg + (i * chunk_stride), - val + (i * chunk_size), - val_len - i * chunk_size); + if (val_len) + ret = _regmap_raw_write_impl(map, reg, val, val_len); return ret; } -- 2.11.0