From patchwork Sat Nov 21 02:45:24 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Martin K. Petersen" X-Patchwork-Id: 38952 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id 9FC9AB7063 for ; Sat, 21 Nov 2009 13:46:47 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754166AbZKUCqg (ORCPT ); Fri, 20 Nov 2009 21:46:36 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754026AbZKUCqe (ORCPT ); Fri, 20 Nov 2009 21:46:34 -0500 Received: from rcsinet11.oracle.com ([148.87.113.123]:42609 "EHLO rgminet11.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753933AbZKUCqc (ORCPT ); Fri, 20 Nov 2009 21:46:32 -0500 Received: from rgminet15.oracle.com (rcsinet15.oracle.com [148.87.113.117]) by rgminet11.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id nAL2kKeY006024 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 21 Nov 2009 02:46:21 GMT Received: from acsmt355.oracle.com (acsmt355.oracle.com [141.146.40.155]) by rgminet15.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id nAL2kCil007009; Sat, 21 Nov 2009 02:46:13 GMT Received: from abhmt021.oracle.com by acsmt355.oracle.com with ESMTP id 511511091258771535; Fri, 20 Nov 2009 18:45:35 -0800 Received: from groovelator.mkp.net (/209.217.122.111) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 20 Nov 2009 18:45:35 -0800 From: "Martin K. Petersen" To: jens.axboe@oracle.com, james.bottomley@hansenpartnership.com, hch@infradead.org, willy@wil.cx, jgarzik@pobox.com, sandeen@redhat.com, rwheeler@redhat.com, linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org Cc: "Martin K. Petersen" Subject: [PATCH 4/4] libata: Fix garbled Trim payload Date: Fri, 20 Nov 2009 21:45:24 -0500 Message-Id: <1258771524-26673-5-git-send-email-martin.petersen@oracle.com> X-Mailer: git-send-email 1.6.0.6 In-Reply-To: <1258771524-26673-1-git-send-email-martin.petersen@oracle.com> References: <1258771524-26673-1-git-send-email-martin.petersen@oracle.com> X-Source-IP: acsmt355.oracle.com [141.146.40.155] X-Auth-Type: Internal IP X-CT-RefId: str=0001.0A090207.4B075471.002E:SCFMA4539814,ss=1,fgs=0 Sender: linux-ide-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org ata_set_lba_range_entries confused indexes into a u64 buffer with byte offsets. Fix this up and document the return value. Update the libata write same translation to reflect this. Signed-off-by: Martin K. Petersen --- drivers/ata/libata-scsi.c | 8 ++++---- include/linux/ata.h | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 08d4ab7..0c496f8 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -2950,7 +2950,7 @@ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc) const u8 *cdb = scmd->cmnd; u64 block; u32 n_block; - u32 size; + u32 trim_sectors; void *buf; /* we may not issue DMA commands if no DMA mode is set */ @@ -2973,13 +2973,13 @@ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc) goto invalid_fld; buf = page_address(sg_page(scsi_sglist(scmd))); - size = ata_set_lba_range_entries(buf, 512 / 8, block, n_block); + trim_sectors = ata_set_lba_range_entries(buf, 512 / 8, block, n_block); tf->protocol = ATA_PROT_DMA; tf->hob_feature = 0; tf->feature = ATA_DSM_TRIM; - tf->hob_nsect = (size / 512) >> 8; - tf->nsect = size / 512; + tf->hob_nsect = trim_sectors >> 8; + tf->nsect = trim_sectors; tf->command = ATA_CMD_DSM; tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48 | ATA_TFLAG_WRITE; diff --git a/include/linux/ata.h b/include/linux/ata.h index b18b2bb..150c9dc 100644 --- a/include/linux/ata.h +++ b/include/linux/ata.h @@ -983,7 +983,8 @@ static inline void ata_id_to_hd_driveid(u16 *id) /* * Write up to 'max' LBA Range Entries to the buffer that will cover the * extent from sector to sector + count. This is used for TRIM and for - * ADD LBA(S) TO NV CACHE PINNED SET. + * ADD LBA(S) TO NV CACHE PINNED SET. Returns number of 512-byte + * sectors required to encode the range. */ static inline unsigned ata_set_lba_range_entries(void *_buffer, unsigned max, u64 sector, unsigned long count) @@ -1001,9 +1002,9 @@ static inline unsigned ata_set_lba_range_entries(void *_buffer, unsigned max, sector += 0xffff; } - max = ALIGN(i * 8, 512); - memset(buffer + i, 0, max - i * 8); - return max; + memset(&buffer[i], 0, (max - i) * 8); + + return ALIGN(i * 8, 512); } static inline int is_multi_taskfile(struct ata_taskfile *tf)