From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.27571.1685919532746148030 for ; Sun, 04 Jun 2023 15:58:52 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=e9iyR3Tn; spf=pass (domain: kernel.org, ip: 139.178.84.217, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1904261369 for ; Sun, 4 Jun 2023 22:58:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80F63C433D2 for ; Sun, 4 Jun 2023 22:58:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685919531; bh=ihdFKg1VJJF7YL6sC5HdMLD0YABjdRgEe+4ccQzO0I4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=e9iyR3Tnq/u42vIVQTuvQ6TJnVEKUhlYA36jpsBMHaGaNGlRn4vZSg3JSKPX1tvqi glvkOXgSo150LtC4/mDzvelLrrlCqCtknK2tQsnR++KA1E9/mD9/QumweyVyefnqpv i/LJX4gKULaO9EMzsjcicTYx+EOFpgycNkjgkLQyi2Z9885D3fbE4lYsdCFngwADWU heC/gL9Q7mOdM/pIK81bQqk0bt2Zoqk+Ed366O7r2axhMZmyUPiMBfKdc/o8diPsPh QHiqrg5fCzNd2AGw8aIZFYeoJ63JBRcSz8Q7Dw8+SXrwjX7qB2k7bi+Q4LiY2RBpaD 7+CsBOzHAUduQ== Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-4f62b512fe2so269897e87.1 for ; Sun, 04 Jun 2023 15:58:51 -0700 (PDT) X-Gm-Message-State: AC+VfDx9bQ+xSPR6m+NkT74zoK5cQlLybzK6vTO8vvd+QlTTjp0nh/JG EJk79inwPF9PgkKkwiSb6NqPyPDWqCeQ9gMORK0= X-Google-Smtp-Source: ACHHUZ5E4+AcfysckTqm0gCELh604AaDIpHN+q1DgoGooLFwLspOFAz/EVATXUn5m0yjAp5pfLR5tghm0zHlNpZkHxI= X-Received: by 2002:a2e:9d10:0:b0:2a7:a719:5943 with SMTP id t16-20020a2e9d10000000b002a7a7195943mr2696407lji.40.1685919529508; Sun, 04 Jun 2023 15:58:49 -0700 (PDT) MIME-Version: 1.0 References: <20230602070946.83730-1-rsingh@ventanamicro.com> In-Reply-To: <20230602070946.83730-1-rsingh@ventanamicro.com> From: "Ard Biesheuvel" Date: Mon, 5 Jun 2023 00:58:37 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [edk2-devel] [PATCH 1/2] MdeModulePkg/Bus/Ata/AtaAtapiPassThru: Fix SIGN_EXTENSION Coverity issue To: devel@edk2.groups.io, rsingh@ventanamicro.com Cc: Hao A Wu , Ray Ni Content-Type: text/plain; charset="UTF-8" On Fri, 2 Jun 2023 at 21:42, Ranbir Singh wrote: > > From: Ranbir Singh > > Line number 1348 does contain a typecast with UINT32, but it is after > all the operations (16-bit left shift followed by OR'ing) are over. > To avoid any SIGN_EXTENSION, typecast the intermediate result after > 16-bit left shift operation immediately with UINT32. > What is wrong with sign extension? > Cc: Hao A Wu > Cc: Ray Ni > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4204 > Signed-off-by: Ranbir Singh > --- > MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c > index 50406fe0270d..70c4ca27dc68 100644 > --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c > +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c > @@ -1345,7 +1345,7 @@ AtaPassThruPassThru ( > // Check logical block size > // > if ((IdentifyData->AtaData.phy_logic_sector_support & BIT12) != 0) { > - BlockSize = (UINT32)(((IdentifyData->AtaData.logic_sector_size_hi << 16) | IdentifyData->AtaData.logic_sector_size_lo) * sizeof (UINT16)); > + BlockSize = (((UINT32)(IdentifyData->AtaData.logic_sector_size_hi << 16) | IdentifyData->AtaData.logic_sector_size_lo) * sizeof (UINT16)); The outer parens are now redundant, which means you're assigning something to BlockSize whose type is based on the type of * sizeof(UINT16), which is unsigned long not unsigned int, so this will produce a truncation warning on some compilers. If you want to suppress the coverity warning without introducing new ones, better to cast the sizeof() to (UINT32).