From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757774AbcGZUPY (ORCPT ); Tue, 26 Jul 2016 16:15:24 -0400 Received: from bh-25.webhostbox.net ([208.91.199.152]:45107 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756117AbcGZUPT (ORCPT ); Tue, 26 Jul 2016 16:15:19 -0400 Date: Tue, 26 Jul 2016 13:15:06 -0700 From: Guenter Roeck To: Brian Norris Cc: Thierry Reding , linux-kernel@vger.kernel.org, Brian Norris , linux-pwm@vger.kernel.org, Javier Martinez Canillas , Enric Balletbo , Dmitry Torokhov , Gwendal Grignou Subject: Re: [PATCH] pwm: cros_ec: add __packed to prevent padding Message-ID: <20160726201506.GB11345@roeck-us.net> References: <1469557333-9497-1-git-send-email-briannorris@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1469557333-9497-1-git-send-email-briannorris@chromium.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-Authenticated_sender: guenter@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: guenter@roeck-us.net X-Authenticated-Sender: bh-25.webhostbox.net: guenter@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Guenter Roeck > --- > 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 >