From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5F35D3ED12D; Tue, 20 Jan 2026 22:21:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768947718; cv=none; b=CYkF54xsCrJsXk9wi5FXpT8jVnvBOf/V73m5g8BnH+MfKFnP2kDYR07UVeEQ2Am/kbOt1AmGIuJMzhn3Lfc8EkXj87gT1ERmu3zSaR5Nzod2/RdXP7OZBF+mQqFNQxnSQMNtd0/7ZkKA8LYN2yjlMhCxgujLcDQRI7zyEmM2mpY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768947718; c=relaxed/simple; bh=IK8D8Xv+ONqo3RFJ8AxmFWNLYJpqQieh7wCmB+tul8k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Rl6iz6MBCc86INnz7QP70r1a7qK6FdSk2S2OscJZb/VJWpRP2xG8AJ5NEM+St6mw6kQ5NAa0n4ZfFHw4LmHVklTQtlD0lQ2ocYfABh2T8jydYRXVr9SrSbkwukUsB3vOBn/hkTVng7W3ulTmNAhjt+F44sETlScrL45Rk4n1fDY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FudbGwBz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FudbGwBz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66A4CC19422; Tue, 20 Jan 2026 22:21:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768947716; bh=IK8D8Xv+ONqo3RFJ8AxmFWNLYJpqQieh7wCmB+tul8k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FudbGwBzYou7nHD9nWyUjG4fZSf4nlql2SX73XBIqVKCIt6rMNRPktAcgX9USwozu zOcA2H+hyeaApk51SoOURjzYDVc9zmchSiIbwdz2j1jriH7BvTQyrzykm6Eo53s8Hp zrF0eUN+yWM3hF/aYMaarnv7Co4qqlfrvImW2p7LzQwMrzsJswiKZkv1FnBxbs093U WFsF7iPDRNFWgE/J4HmkPgM9Jnb9gsGhPkPlfGXXHUAYB4mgWqFhodWexGCxg9bEDy bBw74pex+ej3GL4JFL1MFwnCUkicIbxuh8D1PlnEyGeFtjQDK62SQE3OoZp3X20fA0 ivUPkiBE5dpKQ== Date: Tue, 20 Jan 2026 16:21:55 -0600 From: Rob Herring To: "Peng Fan (OSS)" Cc: Saravana Kannan , Liam Girdwood , Mark Brown , Alexis Czezar Torreno , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Peng Fan Subject: Re: [PATCH 1/5] of: Add of_property_read_[u32,s32]_default Message-ID: <20260120222155.GA1226342-robh@kernel.org> References: <20260119-add_dt_default-v1-0-db4787ea7a9e@nxp.com> <20260119-add_dt_default-v1-1-db4787ea7a9e@nxp.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260119-add_dt_default-v1-1-db4787ea7a9e@nxp.com> On Mon, Jan 19, 2026 at 10:02:54AM +0800, Peng Fan (OSS) wrote: > From: Peng Fan > > Introduce new helper functions of_property_read_u32_default() and > of_property_read_s32_default() to simplify reading optional device tree > properties with a default value. > > A very common pattern in drivers is to provide a default value and let > of_property_read_*() override it when the property is present, e.g.: > > Y = Y_DEFAULT; > of_property_read_u32(np, "prop", &Y); This is how defaults were intended to be handled. > > or equivalently, checking the return value explicitly: > > ret = of_property_read_u32(np, "prop", &val); > if (ret) > Y = Y_DEFAULT; > else > Y = val; This is usually only needed if the variable type is different. Probably the better fix is fix the type difference. > Both forms express the same intent: the property is optional and a > well-defined default should be used if it cannot be read. > > With the new helper, this can be expressed more directly as: > > Y = of_property_read_u32_default(np, "prop", Y_DEFAULT); > > The helpers intentionally ignore the error code and return either the > parsed value or the supplied default. They are meant for optional > properties only. Callers that need to handle or propagate errors should > continue using of_property_read_*() directly. What about u8, u16, etc. and device_property_read_*? I'm really on the fence whether this is all worth it... We may also want to do something like of_property_read() implemented using C11 _Generic(). Not sure if that's worth the churn either. It would make doing some type checks harder. For example I could extract all property names from of_property_read_u32() calls and check their size against the schemas. (I have the first half of that already.) Using _Generic() would make that harder or impossible. Rob