Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1258115imu; Thu, 22 Nov 2018 13:02:45 -0800 (PST) X-Google-Smtp-Source: AJdET5cZ7BPpbGidL5g87At7LlPi6yUl1NjvG8H/2Tma3B/JC5unfyr9aB772F8ymvKZw3k3FIZA X-Received: by 2002:a62:15c3:: with SMTP id 186mr13377182pfv.240.1542920565027; Thu, 22 Nov 2018 13:02:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542920564; cv=none; d=google.com; s=arc-20160816; b=njRp5VihVRCM3U4hdgZFOjlQdxR/OQjnPvU78Z782YXFnB6kK3qFIOyC2DmpGgnzJ6 tfDCwbIdECmaueFF1enRJTthkrXhXBvKotrEXWP9X0gySa6pMcb6EDQOHegD9xSUMS5i RO9PXV/Ifkcp1Cr37C9yBkq1eZluOdyYktXPfl/xMYG4LSVnmg5z2YgfRG8WKVImGAO0 km/fxTPJxZml5XRM15Kbog0f5V+MoA2vnForTZm0IXhSXSZz5D6B6CYgMZlQ7RzwYE06 1a4SwWliR23oBGEkHsz183XMVwOhknFi779kchee8KOsgCMfKBoZ6WNo9QZWakn+y+Lx eK/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=BDfevDNAM/Yv7kMKCdJGCPR62R/gsGg/63P0BcTGbhE=; b=NHMPRfHYL6jDAY0cXF43A7fZJhb46wHTV9mkIwJKrgyWnFCbz2jHMiJptd5/9pbQej Mu8ZjdCo8s4bsBC2mNier0xeXls9j0j9LVsO3EP9KTfs4bDDqMW3Icsl5x3PxbQwVXha 1o8VZseXaORM+YPZuCkCIQdQdjcae8cG43lp0lln+20pDa1me8dPgOq2Pe9K/V+qzZ2H J5XB90ZNYs9bAuLl43zFaRybThXamV2ZZm4bctnXtqAYLiHYqyI9pZv5hf1VWmRdxh4d i0ceTXMLzu7uMEpakN06s/Ma7NQ1VevKe4BV+3PCZ26Kwk0klGaHsComyQL+Y6qGO509 z8nQ== 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 a90si15536669plc.314.2018.11.22.13.01.57; Thu, 22 Nov 2018 13:02:44 -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 S2389617AbeKVR0g (ORCPT + 99 others); Thu, 22 Nov 2018 12:26:36 -0500 Received: from out1.zte.com.cn ([202.103.147.172]:47694 "EHLO mxct.zte.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726958AbeKVR0g (ORCPT ); Thu, 22 Nov 2018 12:26:36 -0500 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id D3A7C766606A3F58CF19; Thu, 22 Nov 2018 14:48:29 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id wAM6mKqD096199; Thu, 22 Nov 2018 14:48:20 +0800 (GMT-8) (envelope-from wang.yi59@zte.com.cn) Received: from fox-host8.localdomain ([10.74.120.8]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2018112214484957-12265950 ; Thu, 22 Nov 2018 14:48:49 +0800 From: Yi Wang To: qiang.zhao@nxp.com Cc: leoyang.li@nxp.com, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, zhong.weidong@zte.com.cn, wang.yi59@zte.com.cn, Wen Yang , Julia Lawall Subject: [PATCH] soc/fsl/qe: fix err handling of ucc_of_parse_tdm Date: Thu, 22 Nov 2018 14:49:45 +0800 Message-Id: <1542869385-48337-1-git-send-email-wang.yi59@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2018-11-22 14:48:49, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2018-11-22 14:48:08, Serialize complete at 2018-11-22 14:48:08 X-MAIL: mse01.zte.com.cn wAM6mKqD096199 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wen Yang Currently there are 2 problems with the ucc_of_parse_tdm function: 1,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. 2,dev 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. This patch fixes them. Suggested-by: Christophe LEROY Signed-off-by: Wen Yang CC: Julia Lawall CC: Zhao Qiang --- drivers/soc/fsl/qe/qe_tdm.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/soc/fsl/qe/qe_tdm.c b/drivers/soc/fsl/qe/qe_tdm.c index f78c346..9a29f0b 100644 --- a/drivers/soc/fsl/qe/qe_tdm.c +++ b/drivers/soc/fsl/qe/qe_tdm.c @@ -47,7 +47,7 @@ int ucc_of_parse_tdm(struct device_node *np, struct ucc_tdm *utdm, struct resource *res; struct device_node *np2; static int siram_init_flag; - struct platform_device *pdev; + struct platform_device *pdev_si, *pdev_siram; sprop = of_get_property(np, "fsl,rx-sync-clock", NULL); if (sprop) { @@ -129,16 +129,16 @@ int ucc_of_parse_tdm(struct device_node *np, struct ucc_tdm *utdm, if (!np2) return -EINVAL; - pdev = of_find_device_by_node(np2); - if (!pdev) { + pdev_si = of_find_device_by_node(np2); + if (!pdev_si) { pr_err("%pOFn: failed to lookup pdev\n", np2); of_node_put(np2); return -EINVAL; } of_node_put(np2); - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - utdm->si_regs = devm_ioremap_resource(&pdev->dev, res); + res = platform_get_resource(pdev_si, IORESOURCE_MEM, 0); + utdm->si_regs = devm_ioremap_resource(&pdev_si->dev, res); if (IS_ERR(utdm->si_regs)) { ret = PTR_ERR(utdm->si_regs); goto err_miss_siram_property; @@ -150,8 +150,8 @@ int ucc_of_parse_tdm(struct device_node *np, struct ucc_tdm *utdm, goto err_miss_siram_property; } - pdev = of_find_device_by_node(np2); - if (!pdev) { + pdev_siram = of_find_device_by_node(np2); + if (!pdev_siram) { ret = -EINVAL; pr_err("%pOFn: failed to lookup pdev\n", np2); of_node_put(np2); @@ -159,8 +159,8 @@ int ucc_of_parse_tdm(struct device_node *np, struct ucc_tdm *utdm, } of_node_put(np2); - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - utdm->siram = devm_ioremap_resource(&pdev->dev, res); + res = platform_get_resource(pdev_siram, IORESOURCE_MEM, 0); + utdm->siram = devm_ioremap_resource(&pdev_siram->dev, res); if (IS_ERR(utdm->siram)) { ret = PTR_ERR(utdm->siram); goto err_miss_siram_property; @@ -174,7 +174,7 @@ 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); + devm_iounmap(&pdev_si->dev, utdm->si_regs); return ret; } EXPORT_SYMBOL(ucc_of_parse_tdm); -- 2.9.5