lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 4 Mar 2020 18:27:36 +0100
From:   Pavel Machek <pavel@...x.de>
To:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc:     linux-kernel@...r.kernel.org, stable@...r.kernel.org,
        Peter Chen <peter.chen@....com>,
        Sasha Levin <sashal@...nel.org>
Subject: Re: [PATCH 4.19 60/87] usb: charger: assign specific number for enum
 value

On Tue 2020-03-03 18:43:51, Greg Kroah-Hartman wrote:
> From: Peter Chen <peter.chen@....com>
> 
> commit ca4b43c14cd88d28cfc6467d2fa075aad6818f1d upstream.
> 
> To work properly on every architectures and compilers, the enum value
> needs to be specific numbers.

All compilers are expected to handle this in the same way, as this is
in C standard. This patch is not neccessary, and should not be in mainline,
either.

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf

6.7.2.2 Enumeration specifiers
Syntax
...
3 The identifiers in an enumerator list are declared as constants that have type int and
may appear wherever such are permitted.107) An enumerator with = defines its
enumeration constant as the value of the constant expression. If the first enumerator has
no =, the value of its enumeration constant is 0. 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. (The use of enumerators with
= may produce enumeration constants with values that duplicate other values in the same
enumeration.) The enumerators of an enumeration are also known as its members.

Best regards,
								Pavel

>  enum usb_charger_type {
> -	UNKNOWN_TYPE,
> -	SDP_TYPE,
> -	DCP_TYPE,
> -	CDP_TYPE,
> -	ACA_TYPE,
> +	UNKNOWN_TYPE = 0,
> +	SDP_TYPE = 1,
> +	DCP_TYPE = 2,
> +	CDP_TYPE = 3,
> +	ACA_TYPE = 4,
>  };
>  
>  /* USB charger state */
>  enum usb_charger_state {
> -	USB_CHARGER_DEFAULT,
> -	USB_CHARGER_PRESENT,
> -	USB_CHARGER_ABSENT,
> +	USB_CHARGER_DEFAULT = 0,
> +	USB_CHARGER_PRESENT = 1,
> +	USB_CHARGER_ABSENT = 2,
>  };
>  
>  #endif /* _UAPI__LINUX_USB_CHARGER_H */
> 

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

Download attachment "signature.asc" of type "application/pgp-signature" (196 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ