Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1017005rwl; Fri, 24 Mar 2023 05:18:45 -0700 (PDT) X-Google-Smtp-Source: AKy350ZDTSD0c7IZSg+UHkP2qXjLX6QSUahzwT/MxpaaxN4w//k9V6CrKt3ptVHbh8x6EJRb2gSA X-Received: by 2002:a17:902:d50c:b0:1a1:7bd7:cc06 with SMTP id b12-20020a170902d50c00b001a17bd7cc06mr2721032plg.43.1679660325045; Fri, 24 Mar 2023 05:18:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679660325; cv=none; d=google.com; s=arc-20160816; b=N0+Of2fbWxTfa7kmCBx2g+YkByoR45AX7pe4VEu6klx4FQJRpeJXF6xzDvwp7ZT5YJ j6YCFIbMFQRLrnB7olwyLk9+hHqmvXrEV7joT1r9Yd1Tybitwtb4jW7gQHETd2slMcxV swqI15aC3zELsPJsfK0zvKRRQQMwjpEDSqFWY3vnaiiSs9vz1moaqE948wT1XT1Giu5z Lif5FKfBxc7j09W6VVc1I9K7qTlW9oruXKAFyNZvQt+YFFNsxKM7jpwAswfFoGeMxlyq w7VGNkUArr3FK40pACAtxl/VUfdJLPPWOJ6cjlFRxndN7ArN/VCY+PZ7zwq/zSpcE/il MDWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=qRTDcSPE3HPmUfIxEpIUzqke0zqXoLOS94joWEAwtU4=; b=pkihJFWpHqtGKPg9mqY+Xd8UI0ACJhHtDHYSgUwpYIwOEs2adhMqXwm4hYLhZrsHNW J2isBKIc7YSRh863aRYzuzWzhSgVUfCAEdkJOlQw6VNyaQnVvT/70UpW7EcOtR5/5Emx duLZljirBi298gBog3WJwECBLnrCrieiD7jaVg0zLkIh1lYIbdY/H6yeOyZsslvvqPtT Nw0fVrjRsz0tZyBEd241u0LJvvCAgGqxOaKpoAKjJsXAdqLt15E0oSmtbuosfHdLNGxf mznPNM2f6wK4a6D3CzpIJ8a0ZqjdZF3H47VyLvLem3UMbJ6z/viyOkL3oa7KjXOVFvk2 v7Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=1UrjijkP; 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=NONE sp=NONE dis=NONE) header.from=lunn.ch Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r137-20020a632b8f000000b0050fbc594e1asi7551942pgr.207.2023.03.24.05.18.31; Fri, 24 Mar 2023 05:18:45 -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=@lunn.ch header.s=20171124 header.b=1UrjijkP; 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=NONE sp=NONE dis=NONE) header.from=lunn.ch Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230230AbjCXMJH (ORCPT + 99 others); Fri, 24 Mar 2023 08:09:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230061AbjCXMJG (ORCPT ); Fri, 24 Mar 2023 08:09:06 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7821799; Fri, 24 Mar 2023 05:09:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=qRTDcSPE3HPmUfIxEpIUzqke0zqXoLOS94joWEAwtU4=; b=1UrjijkPTq+KTeI1ypV+Q0PmdO LP7H6vFJNTWXagLUXC+JDP0Yqe+clgTSs73SI/pXT2X5UfhDc7kfPBrJrE/nnGdDv+3Yqo8WPc/Jg cq8yUmVKH87OIUbb8ov2NU5lXgSZ9pxlkgc7zDpXzvhUungh0j1KEL2gD/bANp5Ddafk=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pfgDv-008Hxo-6S; Fri, 24 Mar 2023 13:08:47 +0100 Date: Fri, 24 Mar 2023 13:08:47 +0100 From: Andrew Lunn To: Maxime Chevallier Cc: Mark Brown , Greg Kroah-Hartman , rafael@kernel.org, Colin Foster , Vladimir Oltean , Lee Jones , davem@davemloft.net, Eric Dumazet , Jakub Kicinski , Paolo Abeni , Heiner Kallweit , Russell King , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, thomas.petazzoni@bootlin.com Subject: Re: [RFC 3/7] regmap: allow upshifting register addresses before performing operations Message-ID: References: <20230324093644.464704-1-maxime.chevallier@bootlin.com> <20230324093644.464704-4-maxime.chevallier@bootlin.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230324093644.464704-4-maxime.chevallier@bootlin.com> X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,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 > index da8996e7a1f1..2ef53936652b 100644 > --- a/drivers/base/regmap/internal.h > +++ b/drivers/base/regmap/internal.h > @@ -31,7 +31,7 @@ struct regmap_format { > size_t buf_size; > size_t reg_bytes; > size_t pad_bytes; > - size_t reg_downshift; > + int reg_shift; Maybe ssize_t to keep with the pattern of using size_t. However, ssize_t is somewhat over sized for a bit shift. So maybe just s8? > size_t val_bytes; > void (*format_write)(struct regmap *map, > unsigned int reg, unsigned int val); > diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c > index 726f59612fd6..c4cde4f45b05 100644 > --- a/drivers/base/regmap/regmap.c > +++ b/drivers/base/regmap/regmap.c > @@ -814,7 +814,7 @@ struct regmap *__regmap_init(struct device *dev, > > map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8); > map->format.pad_bytes = config->pad_bits / 8; > - map->format.reg_downshift = config->reg_downshift; > + map->format.reg_shift = config->reg_shift; > map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8); > map->format.buf_size = DIV_ROUND_UP(config->reg_bits + > config->val_bits + config->pad_bits, 8); > @@ -1679,7 +1679,13 @@ static void regmap_set_work_buf_flag_mask(struct regmap *map, int max_bytes, > static unsigned int regmap_reg_addr(struct regmap *map, unsigned int reg) > { > reg += map->reg_base; > - return reg >> map->format.reg_downshift; > + > + if (map->format.reg_shift > 0) > + reg >>= map->format.reg_shift; > + else if (map->format.reg_shift < 0) > + reg <<= -(map->format.reg_shift); I was wondering about negative shifts. It is apparently undefined behaviour. So this construct is required. Andrew