Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp835452rwl; Fri, 24 Mar 2023 02:39:09 -0700 (PDT) Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=FKAM9pee X-Google-Smtp-Source: AKy350b1bflEQKxwW61DQSqI0aHkxLQrKLtYE2F2S1Dw5m2jgNS0N4OJGb4Cqm91NMCg7Zeqt3NP X-Received: by 2002:a17:90b:1a87:b0:23d:10f2:bda2 with SMTP id ng7-20020a17090b1a8700b0023d10f2bda2mr2432440pjb.30.1679650749224; Fri, 24 Mar 2023 02:39:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679650749; cv=none; d=google.com; s=arc-20160816; b=chuqtcgSxzqIKOq7XFs2Vwx74mxI9LtQ7Hc5lGDoY9QJKT7M4OWFoxdMyjP5WHgtzl JDH/5ke1DsHI9eqEvQi3E/9CJd4Bz7S8p833uCTGKhQrgu7ccnZE2/5jwjKCE0cOshAl LZCnmpb9m8Og1wniTbl+bgb7VFGznWBo3nXQSNZGosM0CoHwVQSiFYNqla0Z4ShPby8Z SqDnvRaa0dTWfryUxhWuwNZHBeCRIqat+OEn/ItJaOuVe8a8iXXJr2oCqKGNty//fttu 3b88ROocrBg+U+9Edt/D43J1AFDBe4RmhHLNeyqgUzfk3JoiG24yDgsijy5yd2fzwh14 fSRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=P2Hf3CyBE1M1ZSzvmtnhpsHtD4ulFZUJigNP2kIndHE=; b=NatnvbhLMP1gR1sUsDdZXot8JwKbimuV9z00RxNn48br7U//V9eKay8oPj4t9drBQT g3xyGxdJPaDbuzQjvn9t0JzHlvmt3BheCUbprQF2fOmJT/8q0JwOgAhLyzpLdF42S8eS KsclpRFPXS2YU96xvkvA+sW+4oQUiXsTFk82JdPGopgnTYTzR2kVWWOq1BbD1lNi3etP M0O8YChpBaacv+Ig2B86Y7Ge2jOXsR+NdnR4o68a+XYcWdzqagbhNseNYWYUiEignPU0 T9IsjvkCsECXe3gP2YRDqBHziDEiqEf9L063YFdPZAt607hRhVamRgfACX8yFJLcH+6+ Ps2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=FKAM9pee; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l12-20020a17090a408c00b0023f5ee62c13si3833173pjg.179.2023.03.24.02.38.58; Fri, 24 Mar 2023 02:39:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=FKAM9pee; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231720AbjCXJhR (ORCPT + 99 others); Fri, 24 Mar 2023 05:37:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231669AbjCXJhF (ORCPT ); Fri, 24 Mar 2023 05:37:05 -0400 Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [IPv6:2001:4b98:dc4:8::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 075C923D99; Fri, 24 Mar 2023 02:37:00 -0700 (PDT) Received: (Authenticated sender: maxime.chevallier@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 823AE10000B; Fri, 24 Mar 2023 09:36:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1679650619; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P2Hf3CyBE1M1ZSzvmtnhpsHtD4ulFZUJigNP2kIndHE=; b=FKAM9peeuA+PH2hCx7Lpn923cVj1ybMQ/8TN4DrVdmhszBYuujwIa6mzcq6xCgz2LFooEH gRPaihCd2v4Gy0JuvaPp2qBAxdy1dvUA09E9hxSdXMXu9NQ5L81dEB8F2ORsDn4CcqMO77 KCHk++76+XpwvI9xaVr8eGz/Kt30CDbE9Gej7Z0Vwrd7j+TZsNtsGAurnFFmB/T+Ba1NWp 2Ep+BbFpM/xJ5heCWM2ML0qRe19ghIGyPd72YWQFQbddCD1pVBE89D/KkTBZxU2SSRMt/1 RSeaafTwQQ6hWslc7H7AWnoTiwLIYBidFhwb9cBE8cP6DDPefu/gf8swCKt/Vw== From: Maxime Chevallier To: Mark Brown , Greg Kroah-Hartman , rafael@kernel.org, Colin Foster , Vladimir Oltean , Lee Jones , davem@davemloft.net, Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Heiner Kallweit , Russell King Cc: Maxime Chevallier , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, thomas.petazzoni@bootlin.com Subject: [RFC 2/7] regmap: check for alignment on translated register addresses Date: Fri, 24 Mar 2023 10:36:39 +0100 Message-Id: <20230324093644.464704-3-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230324093644.464704-1-maxime.chevallier@bootlin.com> References: <20230324093644.464704-1-maxime.chevallier@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With regmap->reg_base and regmap->reg_downshift, the actual register address that is going to be used for the next operation might not be the same as the one we have as an input. Addresses can be offset with reg_base and shifted, which will affect alignment. Check for alignment on the real register address. Signed-off-by: Maxime Chevallier --- drivers/base/regmap/regmap.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index a4e4367648bf..726f59612fd6 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -2016,7 +2016,7 @@ int regmap_write(struct regmap *map, unsigned int reg, unsigned int val) { int ret; - if (!IS_ALIGNED(reg, map->reg_stride)) + if (!IS_ALIGNED(regmap_reg_addr(map, reg), map->reg_stride)) return -EINVAL; map->lock(map->lock_arg); @@ -2043,7 +2043,7 @@ int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val) { int ret; - if (!IS_ALIGNED(reg, map->reg_stride)) + if (!IS_ALIGNED(regmap_reg_addr(map, reg), map->reg_stride)) return -EINVAL; map->lock(map->lock_arg); @@ -2258,7 +2258,7 @@ int regmap_noinc_write(struct regmap *map, unsigned int reg, return -EINVAL; if (val_len % map->format.val_bytes) return -EINVAL; - if (!IS_ALIGNED(reg, map->reg_stride)) + if (!IS_ALIGNED(regmap_reg_addr(map, reg), map->reg_stride)) return -EINVAL; if (val_len == 0) return -EINVAL; @@ -2399,7 +2399,7 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val, int ret = 0, i; size_t val_bytes = map->format.val_bytes; - if (!IS_ALIGNED(reg, map->reg_stride)) + if (!IS_ALIGNED(regmap_reg_addr(map, reg), map->reg_stride)) return -EINVAL; /* @@ -2638,7 +2638,7 @@ static int _regmap_multi_reg_write(struct regmap *map, int reg = regs[i].reg; if (!map->writeable_reg(map->dev, reg)) return -EINVAL; - if (!IS_ALIGNED(reg, map->reg_stride)) + if (!IS_ALIGNED(regmap_reg_addr(map, reg), map->reg_stride)) return -EINVAL; } @@ -2789,7 +2789,7 @@ int regmap_raw_write_async(struct regmap *map, unsigned int reg, if (val_len % map->format.val_bytes) return -EINVAL; - if (!IS_ALIGNED(reg, map->reg_stride)) + if (!IS_ALIGNED(regmap_reg_addr(map, reg), map->reg_stride)) return -EINVAL; map->lock(map->lock_arg); @@ -2911,7 +2911,7 @@ int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val) { int ret; - if (!IS_ALIGNED(reg, map->reg_stride)) + if (!IS_ALIGNED(regmap_reg_addr(map, reg), map->reg_stride)) return -EINVAL; map->lock(map->lock_arg); @@ -2945,7 +2945,7 @@ int regmap_raw_read(struct regmap *map, unsigned int reg, void *val, if (val_len % map->format.val_bytes) return -EINVAL; - if (!IS_ALIGNED(reg, map->reg_stride)) + if (!IS_ALIGNED(regmap_reg_addr(map, reg), map->reg_stride)) return -EINVAL; if (val_count == 0) return -EINVAL; @@ -3040,7 +3040,7 @@ int regmap_noinc_read(struct regmap *map, unsigned int reg, if (val_len % map->format.val_bytes) return -EINVAL; - if (!IS_ALIGNED(reg, map->reg_stride)) + if (!IS_ALIGNED(regmap_reg_addr(map, reg), map->reg_stride)) return -EINVAL; if (val_len == 0) return -EINVAL; @@ -3162,7 +3162,7 @@ int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val, size_t val_bytes = map->format.val_bytes; bool vol = regmap_volatile_range(map, reg, val_count); - if (!IS_ALIGNED(reg, map->reg_stride)) + if (!IS_ALIGNED(regmap_reg_addr(map, reg), map->reg_stride)) return -EINVAL; if (val_count == 0) return -EINVAL; -- 2.39.2