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::241; helo=mail-lf0-x241.google.com; envelope-from=mw@semihalf.com; receiver=edk2-devel@lists.01.org Received: from mail-lf0-x241.google.com (mail-lf0-x241.google.com [IPv6:2a00:1450:4010:c07::241]) (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 0A39C202E6170 for ; Fri, 27 Oct 2017 09:28:49 -0700 (PDT) Received: by mail-lf0-x241.google.com with SMTP id p184so7999274lfe.12 for ; Fri, 27 Oct 2017 09:32:37 -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=NciNr3Ya+JDiOR5JmP43mlANvMK7QVnBlNN5Io6Jve0=; b=XiCse4P5RLt0KZqbh/q6QEegBTi+8VOmADy3DG3nesr+5LTQl6EkE3z8D08GoykceC /7TymwZkkdfUp/APNuILVxo7587tBo0Q6mReN0bWnv5V751+hDUpEUe/m0vutMrFoYjj WC+6IVlVbOazqPLCJJVOejTme9bU7gDly9LIIGRafJldMIVV8Hv0VoK9NTLQ/XNrfnkE yT4fmlrVj7/BUCX47M+wbpuHoCUDJG7YwC9yOjmyx7VuNf3BqKFNqQYEuCwcxGLc1GV6 GC/NOLGg/RpdyeBTluJ/ddQzbdgr1+IDQNtkF9hCfygvw47MqisHvoBo+OI95dn+Smop h7cQ== 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=NciNr3Ya+JDiOR5JmP43mlANvMK7QVnBlNN5Io6Jve0=; b=CFCx5HZR45F973BYpwb/GAaLTMcy3ls32A+K/ECDbn9IZ06LTQxP6XrdBNC/2zV0Wr 4EePypjFL+BNuddjYnIdYuCktU559LQGN4+LhHcii1f+GykRXKPNSqbdb7y2BPXoBjv9 KO0w8qLHVD4mWonN4HIaQvHTkK7QVpLPHjSUI/y75kYmmdLW7m4wAC9xWKMCgQUw+9Ip rmVCxTDXxlqc4/WQXJ94px8jr6jk9WOJ3Q2Z9ZypT4pHbrqvUz31BdNLFII9QByJwqzX +0UToTX0VAA5hViEWByiV30auZdy17C6WyNzxA0jllzZQDAsVCnsNGzcm2LfN1l+fLIC H+cg== X-Gm-Message-State: AMCzsaX12cW/bApd/+POWobi2ub8SNaf47fbCEppo7Xat4vhh4O6KhOg 1AtiTQGAY//0E40HrGCe5UKpE9xIc4I= X-Google-Smtp-Source: ABhQp+RsNdI4N8iCq8MBUKLmwHeZvwYFZmZTvnPgfT/c6fWvg2SPEtffEqZWJcefLLzLSbFiXm+1WA== X-Received: by 10.25.153.136 with SMTP id b130mr347040lfe.233.1509121955207; Fri, 27 Oct 2017 09:32:35 -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 h3sm1569222lfj.26.2017.10.27.09.32.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Oct 2017 09:32:34 -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 18:31:44 +0200 Message-Id: <1509121913-12937-2-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509121913-12937-1-git-send-email-mw@semihalf.com> References: <1509121913-12937-1-git-send-email-mw@semihalf.com> Subject: [platforms: PATCH v3 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 16:28:50 -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 Reviewed-by: Leif Lindholm --- 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