[PATCH] dm: Use explicit numbers for all enum values

Sean Anderson sean.anderson at seco.com
Fri Apr 1 19:22:04 CEST 2022


Hi Michal,

On 4/1/22 6:13 AM, Michal Simek wrote:
> Based on discussion at
> https://lore.kernel.org/r/20200318125003.GA2727094@kroah.com we got
> recommendation to use explicit values for all enum values.
> The patch is following this recommendation.

To comment on Greg's comment

> Yes, but is that guaranteed by the compiler?  I keep getting
> conflicting advice with that.

It's guaranteed by the spec as far back as C89:

> Each subsequent enumerator with no = defines its enumeration constant
> as the value of the constant expression obtained by adding 1 to the
> value of the previous enumeration constant.

from http://port70.net/~nsz/c/c89/c89-draft.html#3.5.2.2

I prefer explicit enumerations when dealing with hardware (to
make it very clear what the value of the constant is). However, when
these enumerations are used only by software, they act as arbitrary
identifiers. They can be changed or rearranged at will without regard to
breaking hardware compatibility. This is especially the case if, like
uclass identifiers, they are entirely internal to U-Boot.

For example, the uclass list is sorted alphabetically. This helps reduce
merge conflicts, since multiple uclasses can be added without trampling
on each other's diff context. This patch would make it such that new
uclass identifiers could only be added to the end of the list, or each
identifier would need to be redefined. This would drastically increase
the incident of merge conflicts in this enum.  For this reason, I don't
think this patch should be applied.

> The same change was also done by commit 31431dd466e7 ("firmware: xilinx:
> Use explicit values for all enum values").
> 
> Signed-off-by: Michal Simek <michal.simek at xilinx.com>
> ---
> 
> I was doing some debug and got uclass ID but without values it is hard to
> find out which uclass it is.

You can get a list of all compiled-in uclasses along with their ids with
the "dm uclass" command.

--Sean


More information about the U-Boot mailing list