pwm: cros-ec: Add __packed to prevent padding
authorBrian Norris <briannorris@chromium.org>
Tue, 26 Jul 2016 18:22:13 +0000 (11:22 -0700)
committerThierry Reding <thierry.reding@gmail.com>
Tue, 6 Sep 2016 08:48:54 +0000 (10:48 +0200)
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>
drivers/pwm/pwm-cros-ec.c

index 99b9acc..f6ca4e8 100644 (file)
@@ -38,7 +38,7 @@ static int cros_ec_pwm_set_duty(struct cros_ec_device *ec, u8 index, u16 duty)
        struct {
                struct cros_ec_command msg;
                struct ec_params_pwm_set_duty params;
-       } buf;
+       } __packed buf;
        struct ec_params_pwm_set_duty *params = &buf.params;
        struct cros_ec_command *msg = &buf.msg;
 
@@ -65,7 +65,7 @@ static int __cros_ec_pwm_get_duty(struct cros_ec_device *ec, u8 index,
                        struct ec_params_pwm_get_duty params;
                        struct ec_response_pwm_get_duty resp;
                };
-       } buf;
+       } __packed buf;
        struct ec_params_pwm_get_duty *params = &buf.params;
        struct ec_response_pwm_get_duty *resp = &buf.resp;
        struct cros_ec_command *msg = &buf.msg;