From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.12 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796292539; b=rKLNUvaXM/YbijvDEcD+lLLLZL4+DTGfFouWgdE0ROxE7xKSZWG+eGyOqgDDCDI4qQWu S+nCVpXYex3G2aIpGSw+lmQxzxlJ1YLKMrqWI/e/CHL0P+pB0bAfMviHVYhKFP+phrFk9 v1aDk/wtclCkrvRlhdi8NbSwi7WQrucUToqxfVu/i1dLJWFQGPa4U+/XUF01NBrzsjQ07 dFvQcnhbSVKa2qE/P0vRLtKKci5EEi+VDa0YiqFidc34v7W/yQWwHKhK78voWuQ5QBaUu JY02R+j4JIep2uzRzKoGprjmUVbqkJ89HHxuE+YCigNhDMNytHRZMhFgmo3taXkbo5w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796292539; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To:Organization; bh=BxAoa82sxWd8UOOPLIkqjzjjLLugMiqGOr3WO6jfDiU=; b=KCKbTLe2xyKmkDwMJ0fDHanuRCRUS4ddr+2ZyDBjB4/TqxnIGpKI7SGG//bJoWWDs+O5 qAgjIrvT5/0HEerrZjTKkeFlvL5IpD8kRx0xBZNiVLdt/P0Vxqvc93oRezJS+RzIWOEih jYGmGBZ/GgO6Gki1EXWl577Uy1/eX1ZWCTYY6hsBw+ZpfOJ0cc0mLUKw5cjKJ7cVYfon1 yYkBdnFxJTk6GEkH0+wKkEdb9iPhma7rvPunuJN85WkS3cpbsZWX0WsstlLaMyjiq1wPg 1NXXazE4dUBWZSKSyLGYGQnSPUQJFWPQXstFRyYCexnXq6soaimew2unK+p1F1q5BFA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=ESk71UwL; arc=none smtp.remote-ip=198.175.65.12 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F983606A32C; Thu, 3 Dec 2026 10:08:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2F983606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=ESk71UwL DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796292539; x=1827828539; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=BxAoa82sxWd8UOOPLIkqjzjjLLugMiqGOr3WO6jfDiU=; b=ESk71UwLzd9R0ZdW7sqX3vE7/WyAA61s6G+TJjLdT3Ap3tkjAm76Upeg 4cfTOgugslShb5h7yp3cmNDRFacK/0lIelDJsldx2EFQls2g2/3GrQy3u otONTktLjrCoL/26TRtIhyD7XP7VeTMHMUYCp/Xo3RTITbXhdL7ZV3CMO ula/jm8fVNKOJrmroozqVULUg2onC0J2s9/Wns96PnkQlNgd42CgTllu4 79leV6b2sYDLJC63MppQuSukga1cmIzBTI39xOHKmTXncQlvpxy1KVGtp 9eX5y7L+MU/JFKRZYQyA8tPMOoZx5YD+uHDr//9Ynb+/6EZkJ3z7xJgCb w==; X-CSE-ConnectionGUID: reWA6c6lRzKp/ygLxSj63g== X-CSE-MsgGUID: 6TWNpIjQTtqUUl52auVppQ== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5167430" X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="5167430" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 02:08:49 -0800 X-CSE-ConnectionGUID: sP9WarCYSWqaL89VaNYAsw== X-CSE-MsgGUID: FVL+0CnfQ6mAxQ0dGFe+aQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="5254199" Received: from inaky-mobl1.amr.corp.intel.com (HELO localhost) ([10.245.244.115]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 02:08:46 -0800 Date: Thu, 3 Dec 2026 12:08:43 +0200 From: Andy Shevchenko To: raffaele.tranfaglia@gmail.com Cc: Mark Brown , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Johan Hovold , Liam Girdwood , Jaroslav Kysela , Takashi Iwai , Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, linux-sound@vger.kernel.org, Neo Chang Subject: Re: [PATCH v3 2/3] regmap: mask values to val_bits on write Message-ID: References: <20261129-regmap-kunit-val-bits-v3-0-499917221d04@gmail.com> <20261129-regmap-kunit-val-bits-v3-2-499917221d04@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261129-regmap-kunit-val-bits-v3-2-499917221d04@gmail.com> Organization: Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo On Sun, Nov 29, 2026 at 12:18:06PM +0000, Raffaele Tranfaglia via B4 Relay wrote: > > regmap_write() takes an unsigned int, also for regmaps with val_bits > smaller than 32. What happens to the bits above val_bits depends on the > bus and on the cache type: > > - buses with a raw write() go through the value formatters, which drop > the bits that do not fit in the formatted value; > - buses and users with only reg_write() get the value unmodified. Some > of them, like the SMBus backends of regmap-i2c, then return -EINVAL; > - the cache may store a value that differs from the one written to the > device. > > For example the adux1020 driver writes ~u16, which is promoted to int, > to a 16-bit register. This works on I2C adapters and fails with -EINVAL > on SMBus-only ones. > > Mask the value to val_bits in _regmap_write(), before updating the > cache, so that all buses and cache types behave the same. Do the same > for the values cached by _regmap_multi_reg_write(), which does not use > _regmap_write() on devices supporting multi register writes. > > val_bits is documented as mandatory, but some users providing their own > reg_read() and reg_write() leave it at 0, for example because their > registers have different sizes. Do not mask values for these. ... > + /* Make sure that the cache and the device see the same value */ > + val &= map->format.val_mask; ... > + * If the regmap_config sets val_bits, any bits of @val above it are ignored. s/are/will be/ ? ... > for (i = 0; i < num_regs; i++) { > - unsigned int val = regs[i].def; > + unsigned int val = regs[i].def & map->format.val_mask; > unsigned int reg = regs[i].reg; I believe I asked for a blank line here and split of the AND operator to make it look like the above. unsigned int val = regs[i].def; unsigned int reg = regs[i].reg; val &= map->format.val_mask; ret = regcache_write(map, reg, val); Blank line is style requirement to split definitions from the code. > ret = regcache_write(map, reg, val); -- With Best Regards, Andy Shevchenko