From nobody Wed Dec 25 14:00:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1509121961176462.68086373310507; Fri, 27 Oct 2017 09:32:41 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 75D1621CEB13B; Fri, 27 Oct 2017 09:28:52 -0700 (PDT) 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) 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) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; 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 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) From: Marcin Wojtas To: edk2-devel@lists.01.org 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: [edk2] [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: , Cc: jinghua@marvell.com, ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, nadavh@marvell.com, David Greeson , neta@marvell.com, kostap@marvell.com MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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/Ma= rvell/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 =3D I2C_SC_FROM_MASTER(This); EFI_I2C_OPERATION *Operation; + EFI_STATUS Status =3D EFI_SUCCESS; =20 ASSERT (RequestPacket !=3D NULL); ASSERT (I2cMasterContext !=3D NULL); @@ -574,33 +575,52 @@ MvI2cStartRequest ( ReadMode =3D Operation->Flags & I2C_FLAG_READ; =20 if (Count =3D=3D 0) { - MvI2cStart ( I2cMasterContext, - (SlaveAddress << 1) | ReadMode, - I2C_TRANSFER_TIMEOUT - ); + Status =3D MvI2cStart (I2cMasterContext, + (SlaveAddress << 1) | ReadMode, + I2C_TRANSFER_TIMEOUT); } else if (!(Operation->Flags & I2C_FLAG_NORESTART)) { - MvI2cRepeatedStart ( I2cMasterContext, - (SlaveAddress << 1) | ReadMode, - I2C_TRANSFER_TIMEOUT - ); + Status =3D MvI2cRepeatedStart (I2cMasterContext, + (SlaveAddress << 1) | ReadMode, + I2C_TRANSFER_TIMEOUT); } =20 + /* 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 =3D=3D 1, - I2C_TRANSFER_TIMEOUT - ); + Status =3D MvI2cRead (I2cMasterContext, + Operation->Buffer, + Operation->LengthInBytes, + &Transmitted, + Count =3D=3D 1, + I2C_TRANSFER_TIMEOUT); + Operation->LengthInBytes =3D Transmitted; } else { - MvI2cWrite ( I2cMasterContext, - Operation->Buffer, - Operation->LengthInBytes, - &Transmitted, - I2C_TRANSFER_TIMEOUT - ); + Status =3D MvI2cWrite (I2cMasterContext, + Operation->Buffer, + Operation->LengthInBytes, + &Transmitted, + I2C_TRANSFER_TIMEOUT); + Operation->LengthInBytes =3D 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 =3D=3D RequestPacket->OperationCount - 1) { MvI2cStop ( I2cMasterContext ); } --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel