Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1450773 > unrolled thread
| Started by | Brian Norris <briannorris@chromium.org> |
|---|---|
| First post | 2016-07-26 20:30 +0200 |
| Last post | 2016-07-26 22:20 +0200 |
| Articles | 3 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH] pwm: cros_ec: add __packed to prevent padding Brian Norris <briannorris@chromium.org> - 2016-07-26 20:30 +0200
Re: [PATCH] pwm: cros_ec: add __packed to prevent padding Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2016-07-26 21:10 +0200
Re: [PATCH] pwm: cros_ec: add __packed to prevent padding Guenter Roeck <linux@roeck-us.net> - 2016-07-26 22:20 +0200
| From | Brian Norris <briannorris@chromium.org> |
|---|---|
| Date | 2016-07-26 20:30 +0200 |
| Subject | [PATCH] pwm: cros_ec: add __packed to prevent padding |
| Message-ID | <rZfh9-5uR-37@gated-at.bofh.it> |
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>
---
Hi Thierry,
I don't know of any bugs directly resolved by this patch, so take it for
v4.8/v4.9 at your discretion.
drivers/pwm/pwm-cros-ec.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/pwm/pwm-cros-ec.c b/drivers/pwm/pwm-cros-ec.c
index 99b9acc1a420..f6ca4e8c6253 100644
--- a/drivers/pwm/pwm-cros-ec.c
+++ b/drivers/pwm/pwm-cros-ec.c
@@ -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;
--
2.8.0.rc3.226.g39d4020
[toc] | [next] | [standalone]
| From | Dmitry Torokhov <dmitry.torokhov@gmail.com> |
|---|---|
| Date | 2016-07-26 21:10 +0200 |
| Message-ID | <rZfTP-5XI-1@gated-at.bofh.it> |
| In reply to | #1450773 |
On Tue, Jul 26, 2016 at 11:22:13AM -0700, Brian Norris wrote:
> 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>
> ---
> Hi Thierry,
>
> I don't know of any bugs directly resolved by this patch, so take it for
> v4.8/v4.9 at your discretion.
>
> drivers/pwm/pwm-cros-ec.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pwm/pwm-cros-ec.c b/drivers/pwm/pwm-cros-ec.c
> index 99b9acc1a420..f6ca4e8c6253 100644
> --- a/drivers/pwm/pwm-cros-ec.c
> +++ b/drivers/pwm/pwm-cros-ec.c
> @@ -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;
> --
> 2.8.0.rc3.226.g39d4020
>
--
Dmitry
[toc] | [prev] | [next] | [standalone]
| From | Guenter Roeck <linux@roeck-us.net> |
|---|---|
| Date | 2016-07-26 22:20 +0200 |
| Message-ID | <rZgZA-6D5-15@gated-at.bofh.it> |
| In reply to | #1450773 |
On Tue, Jul 26, 2016 at 11:22:13AM -0700, Brian Norris wrote:
> 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: Guenter Roeck <linux@roeck-us.net>
> ---
> Hi Thierry,
>
> I don't know of any bugs directly resolved by this patch, so take it for
> v4.8/v4.9 at your discretion.
>
> drivers/pwm/pwm-cros-ec.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pwm/pwm-cros-ec.c b/drivers/pwm/pwm-cros-ec.c
> index 99b9acc1a420..f6ca4e8c6253 100644
> --- a/drivers/pwm/pwm-cros-ec.c
> +++ b/drivers/pwm/pwm-cros-ec.c
> @@ -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;
> --
> 2.8.0.rc3.226.g39d4020
>
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web