Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794992716; b=0izVbU2JFKUFYhyv1Dr9eEWZmxm9oel7intRWMWsORdncbSIoLrLx7gzQSGCPMn2REMy w9z/DCPFdTuTju/hP0/O4WMZJfcDIibG4SIlr+aUsvHJAmuHEkzeUWM61+hJTtY1W90Qv Cencb7FhnaQuP5nVP4H50OPpd/Z/3KA/7f5Hciv+xfIhnUulPJcd80S/8CagDRcMmytFe ALurUN5eWZ9Gxts+pmwAtkndGGR983OAHevxA7ja3JkCXa40qohSDhowLAg6ofnWmnhFI MbvOpZKTt95W4lk7E6OFWapdd0TYmz/i2Y7ufz5EnACizepjMKWxxQsTZtRSpN9J7RQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794992716; 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=374ri7+4MeVZtf5um2Y1DNiMy9roud5hxc7+KcS4KyA=; b=ZOeT8b//w+kheTb6DaP5OLd5VoImkkiqT77adcDc9NLzhyCRcynct96cOeGbMYlhynbi YNVuaaK2PopQ0pGrYk7vfpFRaJbhXWzxDK5KU5Pla7p+8zJr/StMLDo844muH4bYHEfXo Vhx4XV0M+QDg6FM5B1uU8MY7s/KzXsBXbnlEqyXt8YRHXHqRZbAORz8y8cydrS1foBgRH ToUoS/GarKEJtoLbzKLSFS3w4FsA/Cjn4huK7DK4Xr+5mLBj+91fA5P9blKVh/jnFOO0H yQltTuWlRcZhoL75+Yd++TiZihoej5chgkRs9ZdrO+d1/QgQ5J9Bi7cggMarCoKgSIw== 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=MtmMx8sj; arc=none smtp.remote-ip=192.198.163.18 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) (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 33A9B606A31C for ; Wed, 18 Nov 2026 09:05:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 33A9B606A31C 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=MtmMx8sj DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1794992716; x=1826528716; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=JRYvHjc2XzoEsxyTnYYkNUZ2Ub40RofbKnyppuYWcVE=; b=MtmMx8sjCr5vR+qjxpRhT2uNF/AhwpmpnYaQB8iYuwddgwW1eHRpf46g 3e9L02Hoy2kNWR8sQXviPEI4D14YgBRHKkDWvp0weTXSdbJvbq8ZvQFHK hHLP0FCbp66isUf6r15T62wjaQMSFVNv0JbRazYb2WZCzVLFO1q7EiAMP Ihx6d4l3R4NHPI0G+L6txUO2TuJqABPynBSXJ8k4mwsBmbAdvmmxQ7rzV OQ5pRDF2MHj3d98/issjEuwX9g833B9Bjk5YPrAopSP698FMHMMrNrg7K w8MuxjqixGHADcE6nB9dgkpRHsa5xs+NpRQBT6NGSHotohuaVBRFON8a3 A==; X-CSE-ConnectionGUID: /aeuDjIEQmuIkUuf9CDjww== X-CSE-MsgGUID: vsyLOUV5ToevhQKynMg/4g== X-IronPort-AV: E=McAfee;i="6800,10657,11969"; a="3818821" X-IronPort-AV: E=Sophos;i="6.27,219,1787036400"; d="scan'208";a="3818821" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Nov 2026 01:05:02 -0800 X-CSE-ConnectionGUID: +yvOVnxlTj+CX2zSo4rUIA== X-CSE-MsgGUID: nKNRUAYyRJqpgofT/76kLA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,219,1787036400"; d="scan'208";a="10424378" Received: from mkosciow-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.157]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Nov 2026 01:04:59 -0800 Date: Wed, 18 Nov 2026 11:04:56 +0200 From: Andy Shevchenko To: raffaele.tranfaglia@gmail.com Cc: Mark Brown , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Johan Hovold , Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, driver-core@lists.linux.dev Subject: Re: [PATCH RFC] regmap: kunit: add tests for values wider than val_bits Message-ID: References: <20261117-regmap-kunit-val-bits-v1-1-a1cd02063217@gmail.com> X-Mailing-List: driver-core@lists.linux.dev 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: <20261117-regmap-kunit-val-bits-v1-1-a1cd02063217@gmail.com> Organization: Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo On Tue, Nov 17, 2026 at 07:55:14AM +0000, Raffaele Tranfaglia via B4 Relay wrote: Thanks for starting this discussion! My comments below. > Add two test cases writing 0xffffff0f with regmap_write() to a regmap > with val_bits = 16: > > - write_wider_than_val_bits uses the RAM regmap, a bus that only > provides reg_write()/reg_read(); > - raw_write_wider_than_val_bits uses the raw RAM regmap, which goes > through the value formatters. > > Both expect that only the low 16 bits reach the bus and can be read > back. The raw test passes, since regmap_format_16_*() only store 16 > bits. The RAM test currently fails: _regmap_bus_reg_write() hands the > value to bus->reg_write() unmodified, so the bus sees 0xffffff0f. With > the rbtree cache the value is in addition truncated in the cache only, > so the cache and the bus disagree. It means we can't enable this test cases without addressing the underneath implementation(s) of the regmap. I think the proper solution is to cut upper bits on the regmap level, so the cache and HW will see it as expected. > Signed-off-by: Raffaele Tranfaglia > --- > regmap_write() takes an unsigned int, also for regmaps with > val_bits < 32. What happens to the bits above val_bits currently > depends on the bus and on the cache type: > > - buses with raw write() go through the value formatters, which > silently drop the upper bits; > - buses with only reg_write() get the value unmodified. regmap-i2c's > SMBus backends and regmap-fsi then return -EINVAL, others (like > regmap-ram here) take the full value; To make the users' lives easier we should not move the burden on their shoulders to carefully cut the upper bits all the time it might be required. I see the only solution is to fix either globally in regmap core or in each bus and document that somewhere that developers for the new regmap busses won't repeat the same mistakes. > - with a reg_write() bus and the rbtree cache, the cache stores the > truncated value while the bus got the full one. > > This was found in the adux1020 IIO driver, which writes ~u16 (promoted > to int) to a 16-bit register. It works on I2C adapters and fails with > -EINVAL on SMBus-only ones [1]. I am raising it here as other drivers > can hit the same thing. > > The tests in this patch expect masking to val_bits on both kinds of > buses, so the reg_write one fails today. This is only to show the > difference: should regmap_write() mask the value to val_bits for > reg_write() buses, or should it reject such values consistently for all > buses? I can send a patch for whichever is preferred and adjust the > tests accordingly. ... > +static void raw_write_wider_than_val_bits(struct kunit *test) > +{ > + struct regmap *map; > + struct regmap_config config; > + struct regmap_ram_data *data; > + u16 *hw_buf; > + unsigned int rval; Reversed xmas tree order? > + config = raw_regmap_config; > + > + map = gen_raw_regmap(test, &config, &data); > + KUNIT_ASSERT_FALSE(test, IS_ERR(map)); > + if (IS_ERR(map)) > + return; > + > + hw_buf = (u16 *)data->vals; > + > + /* Write a value with bits set above val_bits */ > + KUNIT_EXPECT_EQ(test, 0, regmap_write(map, 0, 0xffffff0f)); > + > + /* The "hardware" should only have seen the low val_bits bits */ > + if (config.val_format_endian == REGMAP_ENDIAN_BIG) > + KUNIT_EXPECT_EQ(test, 0xff0f, > + be16_to_cpu((__force __be16)hw_buf[0])); Do we really need those explicit castings? I think they are already inside the byteorder macros. Also we have be16_to_cpup() and le16_to_cpup() which might help. > + else > + KUNIT_EXPECT_EQ(test, 0xff0f, > + le16_to_cpu((__force __le16)hw_buf[0])); Ditto. > + /* And that is what we should read back */ > + KUNIT_EXPECT_EQ(test, 0, regmap_read(map, 0, &rval)); > + KUNIT_EXPECT_EQ(test, 0xff0f, rval); > +} -- With Best Regards, Andy Shevchenko