diff mbox

[#upstream-fixes] libahci: Fix bug in storing EM messages

Message ID 1277350463.8158.3.camel@zm-desktop
State Not Applicable
Delegated to: David Miller
Headers show

Commit Message

Harry Zhang June 24, 2010, 3:34 a.m. UTC
In function ahci_store_em_buffer(), if the input (signed char*) buffer
contains negative data, the constructed 32-bit long message data may
be wrong.

Signed-off-by: Harry Zhang <harry.zhang@amd.com>
---
 drivers/ata/libahci.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

Comments

Tejun Heo June 24, 2010, 8:30 a.m. UTC | #1
On 06/24/2010 05:34 AM, Harry Zhang wrote:
> In function ahci_store_em_buffer(), if the input (signed char*) buffer
> contains negative data, the constructed 32-bit long message data may
> be wrong.

Explaining why it was wrong would be nice.  Also is adding a comment
explaining why the uchar pointer is needed.  Nothing fancy, just simple
/* avoid sign extension */ should do.

Other than that, Acked-by: Tejun Heo <tj@kernel.org>

Thanks.
Jeff Garzik July 1, 2010, 7:35 p.m. UTC | #2
On 06/23/2010 11:34 PM, Harry Zhang wrote:
> In function ahci_store_em_buffer(), if the input (signed char*) buffer
> contains negative data, the constructed 32-bit long message data may
> be wrong.
>
> Signed-off-by: Harry Zhang<harry.zhang@amd.com>
> ---
>   drivers/ata/libahci.c |    5 +++--
>   1 files changed, 3 insertions(+), 2 deletions(-)

applied


--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
index 1984a6e..7b273f0 100644
--- a/drivers/ata/libahci.c
+++ b/drivers/ata/libahci.c
@@ -324,6 +324,7 @@  static ssize_t ahci_store_em_buffer(struct device *dev,
 	struct ahci_host_priv *hpriv = ap->host->private_data;
 	void __iomem *mmio = hpriv->mmio;
 	void __iomem *em_mmio = mmio + hpriv->em_loc;
+	const unsigned char *msg_buf = buf;
 	u32 em_ctl, msg;
 	unsigned long flags;
 	int i;
@@ -343,8 +344,8 @@  static ssize_t ahci_store_em_buffer(struct device *dev,
 	}
 
 	for (i = 0; i < size; i += 4) {
-		msg = buf[i] | buf[i + 1] << 8 |
-		      buf[i + 2] << 16 | buf[i + 3] << 24;
+		msg = msg_buf[i] | msg_buf[i + 1] << 8 |
+		      msg_buf[i + 2] << 16 | msg_buf[i + 3] << 24;
 		writel(msg, em_mmio + i);
 	}