From nobody Fri Apr 3 11:10:51 2026 Received: from polaris.svanheule.net (polaris.svanheule.net [84.16.241.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D58492475F7 for ; Fri, 20 Feb 2026 15:36:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=84.16.241.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771601820; cv=none; b=SJNx2EwEL9qAisVrvYPt6adCDymWl727/oY9qoBL1D8VCVpFiQG9bmRchB1GscF/RxeizJHQpwpdVIubgWfRQl0V7TZgjxA7fB/EbLHc54apb0iRijUpVMLbZAyNibTxquMgAP50QvqL3svGxnzssV7g1MF7wKqTyAPbqyWSiTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771601820; c=relaxed/simple; bh=/8ylmSr0+m2lg+TV8gRVyHy3fGWsi2N/1/Hfi4WNwy8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=tIxtO+v8Web0B96lj4wynqeHVRJwKIqeXYQwycoByAEvFjDMJ3xWruUxFZ/ahBUgSWzJF49prPPjGKH/JjJUcPE8zBxd/OIJPvdsEigQaPLD+4xmHc3rNNRqO8LWjKkgoClRyUzVf8kDG4hEVpeDHeGTHUfeVmX2bQm5uVSCh08= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=svanheule.net; spf=pass smtp.mailfrom=svanheule.net; dkim=pass (2048-bit key) header.d=svanheule.net header.i=@svanheule.net header.b=G7Jzp/T4; arc=none smtp.client-ip=84.16.241.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=svanheule.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=svanheule.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=svanheule.net header.i=@svanheule.net header.b="G7Jzp/T4" Received: from terra.vega.svanheule.net (2a02-1812-162c-8f00-1e2d-b404-3319-eba8.ip6.access.telenet.be [IPv6:2a02:1812:162c:8f00:1e2d:b404:3319:eba8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: sander@svanheule.net) by polaris.svanheule.net (Postfix) with ESMTPSA id 866E56E865E; Fri, 20 Feb 2026 16:36:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svanheule.net; s=mail1707; t=1771601817; 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; bh=ivPf1oWM4MTuaTG3Zrkx/6DJx6ICXys/AcpbGC1zE3g=; b=G7Jzp/T4s1z+OUBkgaqYVqyz4DYRhHTEcUY/zNwZp15+9UqhkfMTwjB+kHQpFSLpH9lm2r +d3bQp9CgRyUDbDYtbqJpD5cXbTV9jdpCicwp0iPIEmD68DnewDhdEP1b4BtS0RKUWeiNh WbmNkF7O7xj656Wm/XGgSfMLnHPErFWh5wxvgyLsCpYeQmi6LNUKKca+WztOHeXMOa44Li /gWiqWy/LvZpEPDRCZaHoWmz0H/Yi6C0GEuIxWMTz2g91FTLaDaH9ptMRFLSntWO9Hnwl8 EvfbDu3+GD5qTzIED+yS/5C03Gi1wPlrHhOHPg5VzdO7nXd3hspmIrd4kL+kqg== From: Sander Vanheule To: Mark Brown Cc: linux-kernel@vger.kernel.org, Sander Vanheule Subject: [PATCH] regmap: define cleanup helper for regmap_field Date: Fri, 20 Feb 2026 16:36:46 +0100 Message-ID: <20260220153646.494683-1-sander@svanheule.net> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For temporary field allocation, the user has to perform manual cleanup, or rely on devm_regmap_field_alloc() to (eventually) clean up the allocated resources when an error occurs. Add a cleanup helper that takes care of freeing the allocated regmap_field whenever it goes out of scope. This can simplify this example: struct regmap_field *field =3D regmap_field_alloc(...); if (!field) return -ENOMEM; int err =3D regmap_field_write(...); regmap_field_free(field); return err; into the shorter: struct regmap_field *field __free(regmap_field) =3D regmap_field_alloc(= ...); if (!field) return -ENOMEM; return regmap_field_write(...); Signed-off-by: Sander Vanheule --- The included headers in regmap.h are not sorted, so I just included cleanup.h at the bottom of the list. Let me know if the headers should be sorted too, then I can make a preparatory patch. Best, Sander --- include/linux/regmap.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/regmap.h b/include/linux/regmap.h index caff2240bdab..b5508ef4a973 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h @@ -19,6 +19,7 @@ #include #include #include +#include =20 struct module; struct clk; @@ -1460,6 +1461,8 @@ struct regmap_field *regmap_field_alloc(struct regmap= *regmap, struct reg_field reg_field); void regmap_field_free(struct regmap_field *field); =20 +DEFINE_FREE(regmap_field, struct regmap_field *, if (_T) regmap_field_free= (_T)) + struct regmap_field *devm_regmap_field_alloc(struct device *dev, struct regmap *regmap, struct reg_field reg_field); void devm_regmap_field_free(struct device *dev, struct regmap_field *field= ); --=20 2.53.0