From patchwork Sun Aug 16 12:21:21 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 31489 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 bilbo.ozlabs.org (Postfix) with ESMTP id 288F6B6EDF for ; Sun, 16 Aug 2009 22:21:47 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754075AbZHPMVm (ORCPT ); Sun, 16 Aug 2009 08:21:42 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754110AbZHPMVm (ORCPT ); Sun, 16 Aug 2009 08:21:42 -0400 Received: from mail-px0-f196.google.com ([209.85.216.196]:57850 "EHLO mail-px0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754075AbZHPMVl (ORCPT ); Sun, 16 Aug 2009 08:21:41 -0400 Received: by pxi34 with SMTP id 34so845900pxi.4 for ; Sun, 16 Aug 2009 05:21:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=zsBXnEbblx16BGp0sL+zYa95XL0v34phwZAyUwtJ/os=; b=qSUoQqdaREBbK4ke4mexiLAukQz6tfbxNWMhkkjQTGwWRKVYY6lEnlqkpFgMmK4L47 yOVTkzsQ0whbCOCKEB5NCqA2gotIuVaF9+YUV4W2FOspxard1LTy6K7fJzgpXvDv4GUh oA3H5t3lA76n8JmeiAL/yekDvHBJHzpSSeyrQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=GpSqzRZIqzV47OdVgL/ijyIU0rAW4HS0Ww9d3npEkg8aNhEO+TiCzNdnM4FVrFWfMc bzzGZK9QHFuVAi+ufJ9e5rj9EQXSKXmVCUxHhGbQba/lol3AtqeAQI04kg8C/EQBk/5Z YYlwezgteoDv9DDLZOo5+f+xGYVU+ffUeMZlQ= Received: by 10.114.164.40 with SMTP id m40mr3601931wae.225.1250425302483; Sun, 16 Aug 2009 05:21:42 -0700 (PDT) Received: from htj.dyndns.org ([211.179.206.32]) by mx.google.com with ESMTPS id v9sm7377360wah.36.2009.08.16.05.21.41 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 16 Aug 2009 05:21:41 -0700 (PDT) Received: from [192.168.0.5] (unknown [222.99.201.236]) by htj.dyndns.org (Postfix) with ESMTPSA id 0F7F5420A4A28; Sun, 16 Aug 2009 21:21:37 +0900 (KST) Message-ID: <4A87F9C1.5090601@gmail.com> Date: Sun, 16 Aug 2009 21:21:21 +0900 From: Tejun Heo User-Agent: Thunderbird 2.0.0.22 (X11/20090605) MIME-Version: 1.0 To: Atsushi Nemoto CC: jgarzik@pobox.com, linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, stable@kernel.org Subject: [PATCH #upstream-fixes] libata: fix off-by-one error in ata_tf_read_block() References: <20090815.224843.240484147.anemo@mba.ocn.ne.jp> <4A876BC3.3020407@gmail.com> <20090816.183355.89035427.anemo@mba.ocn.ne.jp> In-Reply-To: <20090816.183355.89035427.anemo@mba.ocn.ne.jp> Sender: linux-ide-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org ata_tf_read_block() has off-by-one error when converting CHS address to LBA. The bug isn't very visible because ata_tf_read_block() is used only when generating sense data for a failed RW command and CHS addressing isn't used too often these days. This problem was spotted by Atsushi Nemoto. Signed-off-by: Tejun Heo Reported-by: Atsushi Nemoto --- > Well, I expect fix by you (or other libata hackers) since I think you > can write better warning message and changelog than me ;) In that case, sure. Thanks a lot for the nice spotting. :-) drivers/ata/libata-core.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) -- 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 --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 072ba5e..e71149b 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -709,7 +709,13 @@ u64 ata_tf_read_block(struct ata_taskfile *tf, struct ata_device *dev) head = tf->device & 0xf; sect = tf->lbal; - block = (cyl * dev->heads + head) * dev->sectors + sect; + if (!sect) { + ata_dev_printk(dev, KERN_WARNING, "device reported " + "invalid CHS sector 0\n"); + sect = 1; /* oh well */ + } + + block = (cyl * dev->heads + head) * dev->sectors + sect - 1; } return block;