Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

pwm: cros-ec: Add __packed to prevent padding

While the particular usage in question is likely safe (struct
cros_ec_command is 32-bit aligned, followed by <= 32-bit fields), it's
been suggested this is not a great pattern to follow for the general
case -- for example, if we follow a 'struct cros_ec_command' (which is
32-bit- but not 64-bit-aligned) with a struct that starts with a 64-bit
type (e.g., u64), the compiler may add padding.

Let's add __packed, to inform the compiler of our true intention -- to
have no padding between these struct elements -- and to future proof for
any refactorings that might occur.

Signed-off-by: Brian Norris <briannorris@chromium.org>
Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>

authored by

Brian Norris and committed by
Thierry Reding
065cfbbb cd4b45ac

+2 -2
+2 -2
drivers/pwm/pwm-cros-ec.c
··· 38 38 struct { 39 39 struct cros_ec_command msg; 40 40 struct ec_params_pwm_set_duty params; 41 - } buf; 41 + } __packed buf; 42 42 struct ec_params_pwm_set_duty *params = &buf.params; 43 43 struct cros_ec_command *msg = &buf.msg; 44 44 ··· 65 65 struct ec_params_pwm_get_duty params; 66 66 struct ec_response_pwm_get_duty resp; 67 67 }; 68 - } buf; 68 + } __packed buf; 69 69 struct ec_params_pwm_get_duty *params = &buf.params; 70 70 struct ec_response_pwm_get_duty *resp = &buf.resp; 71 71 struct cros_ec_command *msg = &buf.msg;