From patchwork Tue Apr 1 14:26:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 27549 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f200.google.com (mail-vc0-f200.google.com [209.85.220.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1421620553 for ; Tue, 1 Apr 2014 14:27:06 +0000 (UTC) Received: by mail-vc0-f200.google.com with SMTP id lg15sf23328667vcb.3 for ; Tue, 01 Apr 2014 07:27:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id :mime-version:cc:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=FkkkoEC6tP3EK/0WfWQMaa69j3a3iDDkKeZUle1IBYI=; b=fuJSaPwJIYqvbN3ZP0hXD3zwS3hdbh+D12uYUletU8H6T2SxuD2XXvgwB7e34fvjfm faRgCczDBOQZQ947SH3kF9Ba8N6hFvDEw0MIKZBoC9eneat8ssqmcFaSbf2Pz4rjogMp JowXv8IZ/FFfgRz1oVtT9vaiHDZfziDdNFXzaWVG8yvN6pDVfMJ9Kg9qelgnLm3yQp1u wJkJgd2c0ZxuiuTZwXGcshT79lLitNVe24mS1YIkKKMN4hPkeocWCDy2bC+9qT1CWdUg GOTbexo7k9TNvN9qRSjyBpiBaO1INofc96SW9MTtXJQ1qgl3+g1aw8ZR5X4yxxM2nHsO gFQg== X-Gm-Message-State: ALoCoQkRLGLkKaJ8QmaUX92Xaf6E543hltzhK7d9ELc/JEXJggzF0g9+E/58YjBdOgFHKbnKZogH X-Received: by 10.236.181.74 with SMTP id k50mr11033476yhm.46.1396362426736; Tue, 01 Apr 2014 07:27:06 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.22.167 with SMTP id 36ls19269qgn.55.gmail; Tue, 01 Apr 2014 07:27:06 -0700 (PDT) X-Received: by 10.221.30.14 with SMTP id sa14mr347134vcb.44.1396362426612; Tue, 01 Apr 2014 07:27:06 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id m14si3668262vcn.17.2014.04.01.07.27.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Apr 2014 07:27:06 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id im17so10099723vcb.9 for ; Tue, 01 Apr 2014 07:27:06 -0700 (PDT) X-Received: by 10.220.2.142 with SMTP id 14mr296890vcj.48.1396362426511; Tue, 01 Apr 2014 07:27:06 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.12.8 with SMTP id v8csp241962vcv; Tue, 1 Apr 2014 07:27:05 -0700 (PDT) X-Received: by 10.205.37.78 with SMTP id td14mr25909040bkb.28.1396362425427; Tue, 01 Apr 2014 07:27:05 -0700 (PDT) Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id pd6si9228667bkb.77.2014.04.01.07.27.04 for ; Tue, 01 Apr 2014 07:27:05 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) client-ip=85.214.87.163; Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 729824B77E; Tue, 1 Apr 2014 16:27:04 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id H42xaov4Keo6; Tue, 1 Apr 2014 16:27:04 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6F1754B79B; Tue, 1 Apr 2014 16:27:00 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CD7C74B79B for ; Tue, 1 Apr 2014 16:26:55 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YzPdJNl1SL2J for ; Tue, 1 Apr 2014 16:26:52 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from devils.ext.ti.com (devils.ext.ti.com [198.47.26.153]) by theia.denx.de (Postfix) with ESMTPS id 1DDCC4B77E for ; Tue, 1 Apr 2014 16:26:47 +0200 (CEST) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id s31EQjaE012798; Tue, 1 Apr 2014 09:26:45 -0500 Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id s31EQj6G020697; Tue, 1 Apr 2014 09:26:45 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.174.1; Tue, 1 Apr 2014 09:26:45 -0500 Received: from localhost.localdomain (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s31EQgA1023055; Tue, 1 Apr 2014 09:26:43 -0500 From: Roger Quadros To: Date: Tue, 1 Apr 2014 17:26:40 +0300 Message-ID: <1396362400-32305-1-git-send-email-rogerq@ti.com> X-Mailer: git-send-email 1.8.3.2 MIME-Version: 1.0 Cc: elini@marvell.com, omrii@marvell.com, u-boot@lists.denx.de, aneesh@ti.com, Roger Quadros Subject: [U-Boot] [PATCH] ahci: Fix data abort on multiple scsi resets. X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: rogerq@ti.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Commit 2faf5fb82ed6 introduced a regression that causes a data abort when running scsi init followed by scsi reset. There are 2 problems with the original commit 1) ALLOC_CACHE_ALIGN_BUFFER() allocates memory on the stack but is assigned to ataid[port] and used by other functions. 2) The function ata_scsiop_inquiry() tries to free memory which was never allocated on the heap. Fix these problems by using tmpid as a temporary cache aligned buffer. Allocate memory separately for ataid[port] and re-use it if required. Fixes: 2faf5fb82ed6 (ahci: Fix cache align error messages) Reported-by: Eli Nidam Signed-off-by: Roger Quadros --- drivers/block/ahci.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/block/ahci.c b/drivers/block/ahci.c index a409f63..c8f6573 100644 --- a/drivers/block/ahci.c +++ b/drivers/block/ahci.c @@ -623,6 +623,7 @@ static int ata_scsiop_inquiry(ccb *pccb) 95 - 4, }; u8 fis[20]; + u16 *idbuf; ALLOC_CACHE_ALIGN_BUFFER(u16, tmpid, ATA_ID_WORDS); u8 port; @@ -649,17 +650,25 @@ static int ata_scsiop_inquiry(ccb *pccb) return -EIO; } - if (ataid[port]) - free(ataid[port]); - ataid[port] = tmpid; - ata_swap_buf_le16(tmpid, ATA_ID_WORDS); + if (!ataid[port]) { + ataid[port] = malloc(ATA_ID_WORDS * 2); + if (!ataid[port]) { + printf("%s: No memory for ataid[port]\n", __func__); + return -ENOMEM; + } + } + + idbuf = ataid[port]; + + memcpy(idbuf, tmpid, ATA_ID_WORDS * 2); + ata_swap_buf_le16(idbuf, ATA_ID_WORDS); memcpy(&pccb->pdata[8], "ATA ", 8); - ata_id_strcpy((u16 *) &pccb->pdata[16], &tmpid[ATA_ID_PROD], 16); - ata_id_strcpy((u16 *) &pccb->pdata[32], &tmpid[ATA_ID_FW_REV], 4); + ata_id_strcpy((u16 *)&pccb->pdata[16], &idbuf[ATA_ID_PROD], 16); + ata_id_strcpy((u16 *)&pccb->pdata[32], &idbuf[ATA_ID_FW_REV], 4); #ifdef DEBUG - ata_dump_id(tmpid); + ata_dump_id(idbuf); #endif return 0; }