From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.6 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3AE3CC43381 for ; Fri, 8 Mar 2019 00:18:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F2E472064A for ; Fri, 8 Mar 2019 00:18:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Yu4cl/Ce" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726348AbfCHASq (ORCPT ); Thu, 7 Mar 2019 19:18:46 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:39165 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726172AbfCHASq (ORCPT ); Thu, 7 Mar 2019 19:18:46 -0500 Received: by mail-pf1-f195.google.com with SMTP id i20so12734100pfo.6 for ; Thu, 07 Mar 2019 16:18:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pMrAtyR5r9xC1KvkL1CTb57Dx9giVYGmSgH2BWeg3n0=; b=Yu4cl/Cea1WkMyAr5f9W2QQUF5jbIOhesJZpyZ4880czNGAHrP/+6sHZ/Kn3umigaa d6sn4szwCrj30xgNsm4rtywxZje1PBfU5JgPiK31w169mtpc3B30OJH+LoRwzCXIYlDR gKurhD9G10kZnixAq0xvG03beGYbwUbDi6N/Qc/qlzgsdgjurtMH7s5MmF9n8/iO/8EE 0a/2MouMdipVsVuSU5kxw9yY8j7SbC7BFBOSiQoxZbYMTcIEIEbdR2MKLGlKyajQWWCC 2baEni//CAMiDXdllcDbokN90pCJL3HT91LLLM6pBu+i2Tj0R7l5atnXFc/eczQa9P1C 3tUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pMrAtyR5r9xC1KvkL1CTb57Dx9giVYGmSgH2BWeg3n0=; b=M+qwazPnFUcQampK/Pm0GnfFvGwGEsThKbezilSXrZvCx1bmkq946fyLIJriEPSV6O cecRNAug2otIk98Zjty8Ohv0ugYaJ5W7dDv2vsVzQKb1UQwBG8nFsa+FgjFwbSo/utcS 2lO34w3Qkqdf5PQIjcJgImNoWYsGGo55cz+k/oJFAnp2lsB+RDgpqNAqVfKTJ52C2Q9e cAaJWJSi0VqPOhjSThiEUBcc0UO3rGKycw0EjnckR8N++4JEUiU72cinVKFu6ajNdnoT OTC5vCMNas3QAoTph1arzNdkv1FIXEZwpju1/ibacBUEsT/Eo1rxIujxVIJCG5lKSbqi bs0w== X-Gm-Message-State: APjAAAW7COVTywkgrhznXWHEUiIRzfQOGpNP8QKCLwe8qx1r3j9KfQyi FghA8EQTC/0f0zCKFSrnobXhFQU6e+AIqXq63aISpw== X-Google-Smtp-Source: APXvYqxuzsVs3K+4TZ8tTBfq2k35wOS63/9sSJaVENklPgr56ZvZgOr7DoxBcqaIRcFM5gsZvih80aXfM3zFb9KmgWQ= X-Received: by 2002:a17:902:e85:: with SMTP id 5mr15870178plx.13.1552004324884; Thu, 07 Mar 2019 16:18:44 -0800 (PST) MIME-Version: 1.0 References: <20190307225650.23001-1-natechancellor@gmail.com> In-Reply-To: <20190307225650.23001-1-natechancellor@gmail.com> From: Nick Desaulniers Date: Thu, 7 Mar 2019 16:18:33 -0800 Message-ID: Subject: Re: [PATCH] soc: mediatek: pwrap: Zero initialize rdata in pwrap_init_cipher To: Nathan Chancellor Cc: Matthias Brugger , Linux ARM , linux-mediatek@lists.infradead.org, LKML , clang-built-linux@googlegroups.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 7, 2019 at 2:57 PM Nathan Chancellor wrote: > > When building with -Wsometimes-uninitialized, Clang warns: > > drivers/soc/mediatek/mtk-pmic-wrap.c:1358:6: error: variable 'rdata' is > used uninitialized whenever '||' condition is true > [-Werror,-Wsometimes-uninitialized] > > If pwrap_write returns non-zero, pwrap_read will not be called to > initialize rdata, meaning that we will use some random uninitialized > stack value in our print statement. Zero initialize rdata in case this > happens. > > Link: https://github.com/ClangBuiltLinux/linux/issues/401 > Signed-off-by: Nathan Chancellor > --- > > I don't know if this is better or to just restructure the if statement > below (I'm not an expert in this code so I'll leave that up to the > maintainers to decide). No, I the way you have it here is most correct. That condition writes a value somewhere, reads it back, then compares it. The write or read could fail. Better to just initialize rdata in case the write fails. Thanks for the patch. Reviewed-by: Nick Desaulniers > > drivers/soc/mediatek/mtk-pmic-wrap.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/soc/mediatek/mtk-pmic-wrap.c b/drivers/soc/mediatek/mtk-pmic-wrap.c > index 8236a6c87e19..2f632e8790f7 100644 > --- a/drivers/soc/mediatek/mtk-pmic-wrap.c > +++ b/drivers/soc/mediatek/mtk-pmic-wrap.c > @@ -1281,7 +1281,7 @@ static bool pwrap_is_pmic_cipher_ready(struct pmic_wrapper *wrp) > static int pwrap_init_cipher(struct pmic_wrapper *wrp) > { > int ret; > - u32 rdata; > + u32 rdata = 0; > > pwrap_writel(wrp, 0x1, PWRAP_CIPHER_SWRST); > pwrap_writel(wrp, 0x0, PWRAP_CIPHER_SWRST); > -- > 2.21.0 > -- Thanks, ~Nick Desaulniers From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.0 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46655C43381 for ; Fri, 8 Mar 2019 00:18:56 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1362E20652 for ; Fri, 8 Mar 2019 00:18:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="c9v0iT2T"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Yu4cl/Ce" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1362E20652 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=EcmWhh5Vy+JidKVvmvmK7wLbrb/0EAOM/qglqGEPiXs=; b=c9v0iT2TWtci9F Zh1rW6PaBFn1SmPmHCOjQKeVoQfpR7DKjggEXTHEs6ZldxSV1RAMCrgNhE2FACiGOPCvWdnSEfJEf oFfQnxHNEVrGh4gSw17jUgqvvKp8vFmMZVjTK8oUW0xTqCDRjqmoJHfgr+AnxCC+oZUMzlpEiYdFo XJmrgJsGM4XnTDxd4YfNB/Sj+Uk5vVA95STh2zcR5hRFYTi46ytHXIwVi3dQ3wIhPvCC6uuVVDenZ jJYT1eBcEbGEjLbkkOseuZyDDg2eK++BkdssyxSJkbITX50/DflLrhUhK8iOFg73k6G7r+7xJxqZ8 QDZL7TrWn9/uzBhKBI9g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h23Dt-0002VX-Tq; Fri, 08 Mar 2019 00:18:49 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h23Dp-0002UR-Iw for linux-arm-kernel@lists.infradead.org; Fri, 08 Mar 2019 00:18:47 +0000 Received: by mail-pf1-x441.google.com with SMTP id d25so12731610pfn.8 for ; Thu, 07 Mar 2019 16:18:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pMrAtyR5r9xC1KvkL1CTb57Dx9giVYGmSgH2BWeg3n0=; b=Yu4cl/Cea1WkMyAr5f9W2QQUF5jbIOhesJZpyZ4880czNGAHrP/+6sHZ/Kn3umigaa d6sn4szwCrj30xgNsm4rtywxZje1PBfU5JgPiK31w169mtpc3B30OJH+LoRwzCXIYlDR gKurhD9G10kZnixAq0xvG03beGYbwUbDi6N/Qc/qlzgsdgjurtMH7s5MmF9n8/iO/8EE 0a/2MouMdipVsVuSU5kxw9yY8j7SbC7BFBOSiQoxZbYMTcIEIEbdR2MKLGlKyajQWWCC 2baEni//CAMiDXdllcDbokN90pCJL3HT91LLLM6pBu+i2Tj0R7l5atnXFc/eczQa9P1C 3tUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pMrAtyR5r9xC1KvkL1CTb57Dx9giVYGmSgH2BWeg3n0=; b=UEStitaC2tSsVj3w0wz1VfdHFBgn5Z5BIaDCqVroFvHLNFMJU0vGg1nEWXXp/MU8Jt jLlntD3qzsKCXfYvOwQ/R1kklmlBZGTAXp9dn0x2yEfGpvDYFuuo2qsIHXCgt/8UfGFT mvvpHMFXaNkAD5VYJ8iy4E5VDn9wDuMGS/wuUeQAodyYtq8qfPBo/nmIqgSj5BVf8Tr0 Wt8ofSknafVbDKl8+qQtmC46blqvn9knVyJbQNp1j9/4bACLpfQY9ttztmJApGtPHBRj wWqJl3x5L9QSruF3PKCnGTZKw85URi93NLqlF2tU37e/0uHnnAdVv8NRhRN0FtWOo5A6 Gxdw== X-Gm-Message-State: APjAAAWR4ZJnodFek0COjKhqnch629LHuQzwsqtwNfMLYdFGwz8KWbIn EhU9gj9eS0AF2qO/nN6JV9HRim2gEVRIkMfvcDtBlA== X-Google-Smtp-Source: APXvYqxuzsVs3K+4TZ8tTBfq2k35wOS63/9sSJaVENklPgr56ZvZgOr7DoxBcqaIRcFM5gsZvih80aXfM3zFb9KmgWQ= X-Received: by 2002:a17:902:e85:: with SMTP id 5mr15870178plx.13.1552004324884; Thu, 07 Mar 2019 16:18:44 -0800 (PST) MIME-Version: 1.0 References: <20190307225650.23001-1-natechancellor@gmail.com> In-Reply-To: <20190307225650.23001-1-natechancellor@gmail.com> From: Nick Desaulniers Date: Thu, 7 Mar 2019 16:18:33 -0800 Message-ID: Subject: Re: [PATCH] soc: mediatek: pwrap: Zero initialize rdata in pwrap_init_cipher To: Nathan Chancellor X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190307_161845_645365_92264A3F X-CRM114-Status: GOOD ( 17.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Matthias Brugger , clang-built-linux@googlegroups.com, linux-mediatek@lists.infradead.org, LKML , Linux ARM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Mar 7, 2019 at 2:57 PM Nathan Chancellor wrote: > > When building with -Wsometimes-uninitialized, Clang warns: > > drivers/soc/mediatek/mtk-pmic-wrap.c:1358:6: error: variable 'rdata' is > used uninitialized whenever '||' condition is true > [-Werror,-Wsometimes-uninitialized] > > If pwrap_write returns non-zero, pwrap_read will not be called to > initialize rdata, meaning that we will use some random uninitialized > stack value in our print statement. Zero initialize rdata in case this > happens. > > Link: https://github.com/ClangBuiltLinux/linux/issues/401 > Signed-off-by: Nathan Chancellor > --- > > I don't know if this is better or to just restructure the if statement > below (I'm not an expert in this code so I'll leave that up to the > maintainers to decide). No, I the way you have it here is most correct. That condition writes a value somewhere, reads it back, then compares it. The write or read could fail. Better to just initialize rdata in case the write fails. Thanks for the patch. Reviewed-by: Nick Desaulniers > > drivers/soc/mediatek/mtk-pmic-wrap.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/soc/mediatek/mtk-pmic-wrap.c b/drivers/soc/mediatek/mtk-pmic-wrap.c > index 8236a6c87e19..2f632e8790f7 100644 > --- a/drivers/soc/mediatek/mtk-pmic-wrap.c > +++ b/drivers/soc/mediatek/mtk-pmic-wrap.c > @@ -1281,7 +1281,7 @@ static bool pwrap_is_pmic_cipher_ready(struct pmic_wrapper *wrp) > static int pwrap_init_cipher(struct pmic_wrapper *wrp) > { > int ret; > - u32 rdata; > + u32 rdata = 0; > > pwrap_writel(wrp, 0x1, PWRAP_CIPHER_SWRST); > pwrap_writel(wrp, 0x0, PWRAP_CIPHER_SWRST); > -- > 2.21.0 > -- Thanks, ~Nick Desaulniers _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel