Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1891286imu; Wed, 21 Nov 2018 03:40:03 -0800 (PST) X-Google-Smtp-Source: AJdET5f26J1eYY0ZBTDpl5xF+wxkcf9jpkovEJLBIdmjzqbcbU0Mpc3BibECUrglJnvH7KSWKaK/ X-Received: by 2002:aa7:814f:: with SMTP id d15-v6mr6546406pfn.78.1542800403812; Wed, 21 Nov 2018 03:40:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542800403; cv=none; d=google.com; s=arc-20160816; b=Ghvo1Ec4IahQ7DHtHLZwZlyobyEve2cYd3tdRULuDr8+KQamS4qr7v+Gl+Gg+5+skR KxYXUI2iTb86d1X+xNeeOIyyZ1VehEhrm1qRomf91v2lwVtbYnEpZioYHx9nMLmEpxCO dOYBXz3JF7L/Ljr8XZiaz5F5mTa0EzOOrPzoFaJlnJzQJmTTgMsGd1KE1Oly1YmVMO6B n4AGvpc0AHOQRoPdXhTslL8btcjRbz8N9/dmOkZH90/8Fo+CXWlKaZ2dUVTxFaNSaeR2 DQLggi3xMr4Cti6IPKcw1vswR+joZ+ERIEmDgnf2pLqhFpWsREJP9QJxL1+R37ua+gou EqDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=Kj2cuLB8Ig8PhFTvu3CPIGokihbAueuw3WkdUnXBbFo=; b=iS9HM2uLaaKDJfNezZFduvIlDJQ29nfNTSZ9/yN1VtsHVzkYAt4GttkjpOk1w/t2NR /yAKTHPjFDDwQXTbZMOtBwDY0FwEOKsNDzJzGS3l3QVPeD/5ALZu5yhSLTOrpt4CGNyd PxtmNm9DY0nDqHcwB8cCQxoST0k5SMR+NlktZpER2wRdsz4Ru++MBFR3WG6P2XZxSSCE Uz+fCsnAnQC5tjk5HRVxbibtpEhYcBGqTtaOz4HpDJVkm1QMneYv/hnvLcce5Ovr6OYU MYZ/z7pKbeEHT1uqfygee8BuJh+mzCIVRPST/C7tAOg88RPFYafaCHa1PPwHQ7zeAD9/ YEOQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h1-v6si48335152pld.332.2018.11.21.03.39.48; Wed, 21 Nov 2018 03:40:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729563AbeKUVTV (ORCPT + 99 others); Wed, 21 Nov 2018 16:19:21 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:20916 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726729AbeKUVTU (ORCPT ); Wed, 21 Nov 2018 16:19:20 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 430K3P5wcTz9vF7K; Wed, 21 Nov 2018 11:45:21 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id anB1K_LhuOkF; Wed, 21 Nov 2018 11:45:21 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 430K3P5Pw8z9vF7R; Wed, 21 Nov 2018 11:45:21 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 67FAC8B808; Wed, 21 Nov 2018 11:45:26 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id lC8aQVMCjNZT; Wed, 21 Nov 2018 11:45:26 +0100 (CET) Received: from PO15451 (po15451.idsi0.si.c-s.fr [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 2F26F8B809; Wed, 21 Nov 2018 11:45:26 +0100 (CET) Subject: Re: [PATCH 2/4] soc/fsl/qe: fix potential NULL pointer dereference in ucc_of_parse_tdm To: Wen Yang , qiang.zhao@nxp.com Cc: wang.yi59@zte.com.cn, zhong.weidong@zte.com.cn, linux-kernel@vger.kernel.org, leoyang.li@nxp.com, Julia Lawall , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org References: <1542786111-18648-1-git-send-email-wen.yang99@zte.com.cn> From: Christophe LEROY Message-ID: Date: Wed, 21 Nov 2018 11:45:26 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: <1542786111-18648-1-git-send-email-wen.yang99@zte.com.cn> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 21/11/2018 à 08:41, Wen Yang a écrit : > This patch fixes a possible null pointer dereference in > ucc_of_parse_tdm, detected by the semantic patch > deref_null.cocci, with the following warning: > > ./drivers/soc/fsl/qe/qe_tdm.c:177:21-24: ERROR: pdev is NULL but dereferenced. > > The following code has potential null pointer references: > pdev = of_find_device_by_node(np2); > if (!pdev) { > ret = -EINVAL; > pr_err("%pOFn: failed to lookup pdev\n", np2); > of_node_put(np2); > goto err_miss_siram_property; > } > ... > err_miss_siram_property: > devm_iounmap(&pdev->dev, utdm->si_regs); > > Signed-off-by: Wen Yang > Reviewed-by: Tan Hu > CC: Julia Lawall > --- > drivers/soc/fsl/qe/qe_tdm.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/soc/fsl/qe/qe_tdm.c b/drivers/soc/fsl/qe/qe_tdm.c > index f78c346..166378b 100644 > --- a/drivers/soc/fsl/qe/qe_tdm.c > +++ b/drivers/soc/fsl/qe/qe_tdm.c > @@ -174,7 +174,8 @@ int ucc_of_parse_tdm(struct device_node *np, struct ucc_tdm *utdm, > return ret; > > err_miss_siram_property: > - devm_iounmap(&pdev->dev, utdm->si_regs); > + if (pdev) > + devm_iounmap(&pdev->dev, utdm->si_regs); You are just hiding the issue, not fixing it. The problem is that pdev gets modified, so in any case that devm_iounmap() will fail even when the new pdev is valid, because the iomap was done with a different pdev. Christophe > return ret; > } > EXPORT_SYMBOL(ucc_of_parse_tdm); >