linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: linux-input@vger.kernel.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>, linux-kernel@vger.kernel.org
Subject: [PATCH] Input: ims-pcu - remove unneeded get_unaligned_xxx
Date: Fri, 3 Jan 2014 21:28:00 -0800	[thread overview]
Message-ID: <20140104052756.GA32561@core.coreip.homeip.net> (raw)

pcu->cmd_buf[IMS_PCU_DATA_OFFSET] is word aligned so we do not need to use
get_unaligned_le16 to access it.

Also let's add build time check to make sure it stays aligned.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/input/misc/ims-pcu.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
index 513ecdf..b8f1029 100644
--- a/drivers/input/misc/ims-pcu.c
+++ b/drivers/input/misc/ims-pcu.c
@@ -116,6 +116,8 @@ struct ims_pcu {
 	bool setup_complete; /* Input and LED devices have been created */
 };
 
+#define IMS_PCU_CHECK_CMD_BUF_ALIGNMENT(offset, alignment)	\
+	IS_ALIGNED(offsetof(struct ims_pcu, cmd_buf[offset]), alignment)
 
 /*********************************************************************
  *             Buttons Input device support                          *
@@ -999,8 +1001,10 @@ ims_pcu_backlight_get_brightness(struct led_classdev *cdev)
 		/* Assume the LED is OFF */
 		brightness = LED_OFF;
 	} else {
-		brightness =
-			get_unaligned_le16(&pcu->cmd_buf[IMS_PCU_DATA_OFFSET]);
+		BUILD_BUG_ON(!IMS_PCU_CHECK_CMD_BUF_ALIGNMENT(
+				IMS_PCU_DATA_OFFSET, 2));
+		brightness = le16_to_cpup(
+				(__le16 *)&pcu->cmd_buf[IMS_PCU_DATA_OFFSET]);
 	}
 
 	mutex_unlock(&pcu->cmd_mutex);
-- 
1.8.4.2


-- 
Dmitry

             reply	other threads:[~2014-01-04  5:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-04  5:28 Dmitry Torokhov [this message]
2014-01-04  5:52 ` [PATCH] Input: ims-pcu - remove unneeded get_unaligned_xxx Andrey Smirnov
2014-01-04  6:16   ` Dmitry Torokhov
2014-01-04  6:49     ` Andrey Smirnov
2014-01-04  7:46       ` Dmitry Torokhov
2014-01-04 17:41         ` Andrey Smirnov
2014-01-04 22:32           ` Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140104052756.GA32561@core.coreip.homeip.net \
    --to=dmitry.torokhov@gmail.com \
    --cc=andrew.smirnov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).