From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: None (no SPF record) identity=mailfrom; client-ip=2a00:1450:4010:c07::243; helo=mail-lf0-x243.google.com; envelope-from=mw@semihalf.com; receiver=edk2-devel@lists.01.org Received: from mail-lf0-x243.google.com (mail-lf0-x243.google.com [IPv6:2a00:1450:4010:c07::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 31B322034A875 for ; Thu, 26 Oct 2017 18:10:44 -0700 (PDT) Received: by mail-lf0-x243.google.com with SMTP id r129so5661606lff.8 for ; Thu, 26 Oct 2017 18:14:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pXZDa8JIbpsNYk32B/nngHSyy2diq8o7iUTlMRNNjY4=; b=hllEdROiVWskoBpCVbT97ZOPfNJmgZR+q2F0ThpXkdIlrLjvyq5tW1DxlB8eQ9yOWT FpB4Ph8qVqpXB6wOiyMS8PDIzrhSvFEZblAhj5Xy3M1BEsZ001uANPaKDX+d1tEkXXcH G89BF0b0HJ+co5Na47ajg+eAEwu56VvQ25u5msvquhaT0Vj75NQXar5wf5LlVZeLkec0 wXmyVgRpdW819AqNiw/w2b1Htpf/bhIqp1v0RuAThiN36ojeHGkr40oSMLlWCca4E7l2 RMFv5+siAO1lfOu42WdEUj2PvcZS7mjiR10XleZtmugVIb5ughthT1ekANG1kv+wdy8s 1qZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pXZDa8JIbpsNYk32B/nngHSyy2diq8o7iUTlMRNNjY4=; b=biF7E2Ccs5PP5F6uz6/aqMDIw5Z6Zk8z+5ZUj+QkNTyfgERB1dfA5YSlN09wsb+Tr/ gLrzq13RfMyrUPhJsbOe4/lM1hEwV+cEOY5CUz5pPhkdhRIO0ssyoqGgebUttD54FNnL /GymERxsizOtxOJxNIW7Y+qo22WnCKes5Mu2OX3+98YnqAXD6SaX+WN7/dvCnZRqG95i FQE4U3nzliboo11QpBIY5h2vNLUmRS8uo86R8FLBQkHlnLaSOt55LZfHbhFiLldMS5nu FAUb11EHSOdwrFvouKm1bgxY42h9p/U7ZWXxoR9ykOD25JggCLX6qEVj+M6a4P115vcS IhFw== X-Gm-Message-State: AMCzsaX1xipB7QIc6U/uTC6qZVEvcstQORc2If7DNOi3/99mUd4kG8Nm JHLsLHD1qKLql8zTVEvF0wuEbAAMJsA= X-Google-Smtp-Source: ABhQp+T066dkn/ybBbIR0BOJTxej7g0t8/KcwBQHt4SDCpkmhErEgebNKctxJ7mHFpzNROfC9S3xlw== X-Received: by 10.25.115.14 with SMTP id o14mr7181939lfc.79.1509066868842; Thu, 26 Oct 2017 18:14:28 -0700 (PDT) Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id m9sm1675702ljb.61.2017.10.26.18.14.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Oct 2017 18:14:27 -0700 (PDT) From: Marcin Wojtas To: edk2-devel@lists.01.org Cc: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, nadavh@marvell.com, neta@marvell.com, kostap@marvell.com, jinghua@marvell.com, mw@semihalf.com, jsd@semihalf.com, David Greeson Date: Fri, 27 Oct 2017 03:13:43 +0200 Message-Id: <1509066832-5285-2-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509066832-5285-1-git-send-email-mw@semihalf.com> References: <1509066832-5285-1-git-send-email-mw@semihalf.com> Subject: [platforms: PATCH v2 01/10] Marvell/Drivers: MvI2cDxe: Abort transaction immediately upon fail X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Oct 2017 01:10:44 -0000 From: David Greeson Although the I2C transaction routines were prepared to return their status, they were never used. This could cause bus lock-up e.g. in case of failing to send a slave address, the data transfer was attempted to be continued anyway. This patch fixes faulty behavior by checking transaction status and stopping it immediately, once the fail is detected. On the occasion fix style around modified functions calls. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: David Greeson [Style adjustment and cleanup] Signed-off-by: Marcin Wojtas --- Platform/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.c | 62 +++++++++++++------- 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/Platform/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.c b/Platform/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.c index d85ee0b..b4599d2 100755 --- a/Platform/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.c +++ b/Platform/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.c @@ -565,6 +565,7 @@ MvI2cStartRequest ( UINTN Transmitted; I2C_MASTER_CONTEXT *I2cMasterContext = I2C_SC_FROM_MASTER(This); EFI_I2C_OPERATION *Operation; + EFI_STATUS Status = EFI_SUCCESS; ASSERT (RequestPacket != NULL); ASSERT (I2cMasterContext != NULL); @@ -574,33 +575,52 @@ MvI2cStartRequest ( ReadMode = Operation->Flags & I2C_FLAG_READ; if (Count == 0) { - MvI2cStart ( I2cMasterContext, - (SlaveAddress << 1) | ReadMode, - I2C_TRANSFER_TIMEOUT - ); + Status = MvI2cStart (I2cMasterContext, + (SlaveAddress << 1) | ReadMode, + I2C_TRANSFER_TIMEOUT); } else if (!(Operation->Flags & I2C_FLAG_NORESTART)) { - MvI2cRepeatedStart ( I2cMasterContext, - (SlaveAddress << 1) | ReadMode, - I2C_TRANSFER_TIMEOUT - ); + Status = MvI2cRepeatedStart (I2cMasterContext, + (SlaveAddress << 1) | ReadMode, + I2C_TRANSFER_TIMEOUT); } + /* I2C transaction was aborted, so stop further transactions */ + if (EFI_ERROR (Status)) { + MvI2cStop (I2cMasterContext); + break; + } + + /* + * If sending the slave address was successful, + * proceed to read or write section. + */ if (ReadMode) { - MvI2cRead ( I2cMasterContext, - Operation->Buffer, - Operation->LengthInBytes, - &Transmitted, - Count == 1, - I2C_TRANSFER_TIMEOUT - ); + Status = MvI2cRead (I2cMasterContext, + Operation->Buffer, + Operation->LengthInBytes, + &Transmitted, + Count == 1, + I2C_TRANSFER_TIMEOUT); + Operation->LengthInBytes = Transmitted; } else { - MvI2cWrite ( I2cMasterContext, - Operation->Buffer, - Operation->LengthInBytes, - &Transmitted, - I2C_TRANSFER_TIMEOUT - ); + Status = MvI2cWrite (I2cMasterContext, + Operation->Buffer, + Operation->LengthInBytes, + &Transmitted, + I2C_TRANSFER_TIMEOUT); + Operation->LengthInBytes = Transmitted; } + + /* + * The I2C read or write transaction failed. + * Stop the I2C transaction. + */ + if (EFI_ERROR (Status)) { + MvI2cStop (I2cMasterContext); + break; + } + + /* Check if there is any more data to be sent */ if (Count == RequestPacket->OperationCount - 1) { MvI2cStop ( I2cMasterContext ); } -- 2.7.4