Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp112062ybg; Mon, 8 Jun 2020 17:57:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8+OoWblBbMRZpMme7FiBmR9BoChig6utCMsCO6FLmH8YW97mMHCHnuQKj04mDBQH5/Sc+ X-Received: by 2002:a17:907:20f4:: with SMTP id rh20mr22799118ejb.55.1591664222755; Mon, 08 Jun 2020 17:57:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591664222; cv=none; d=google.com; s=arc-20160816; b=mQgdgBEAf1SOzX8wgXvTyf6DUIR7TtcxujW7naQdiJ8J1Lg7C1hTEZIT3VeARwVcHf bpIHFIamclUSTkjvc3+U94tr1QzXdldeUjtR2RK6ou2kvkg5D7L3g3RVFLyJLFgO3Oe7 fYHxMWhb0L8IJaPc+PrUhM4LTMS/gqjzNEKy8CtKXZhiYfnd6gVXH3cXwlVMGMpk8Nf6 6SSMNWb0Y2VrnhBCBvKFLHHZ+ha82YtfZChvtIPKiexMMeUGQcXRiCIYEYZocqzwnaPF OM401v+84RecQHuaGruExXiX1ERpXYTJpbKjgftdOmTS8O+8egoBZJVqqP0QWY5K1Yp7 D89Q== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=I7FLvfX+HQnYtN/oprRgl0s/Mpn2YpiT9Am2PZaTe3o=; b=tuMx1lNheaauooKW8GTbKc3/qd9GskW+NJZKsNQItRC/ycAQcMc6fM76NJdyktYvCS Y82PtTDlGiHGTfe0UljRlU/TKBQ1HFUtnzqBbxyl9CESDmjghbL/GlxCqPH6xChqhI4r 6pPs814pr3u3NWUIqM3JPhwEUjilR9XguOy6RJ9e6o2Fi1jwOJXOpZTaFtaWOLoKNrg3 2O3THFgk7uW+fSCjLJLMz8akSzRx30l6F53rHx7PMQbR7BJSz+Nfk4OaHZsupZFUqb6k uLis9RlBW0GNYMXNefCUEdIkyXa8pp5oQWBbZi6uBZ+tfs0RFkMJn7IT5VN2OcvWktzs fX1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KTzcm84W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id be4si9813919edb.610.2020.06.08.17.56.39; Mon, 08 Jun 2020 17:57:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KTzcm84W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731768AbgFIAyp (ORCPT + 99 others); Mon, 8 Jun 2020 20:54:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:55234 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726970AbgFHXJb (ORCPT ); Mon, 8 Jun 2020 19:09:31 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BAA94208B8; Mon, 8 Jun 2020 23:09:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657770; bh=Ua04pMjpye9PITZFvdpeHXmH7tJJFLNH+IV3ssmzsA0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KTzcm84WpsKqitHrQ1vBbGILl8PTvX4kQcMz+3k+pDP3uoFHoZY22S6+lbsJmyW7n emu+57FMPgthyLKNwdU1kzc09QhmUkuChu+6+pvNObsVXSPEux9WHa/luFMch/BRCf o8b3jU/48/GEpEzSP0LF6/iObKQ0dppmthzuzO/k= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Wei Yongjun , Grygorii Strashko , "David S . Miller" , Sasha Levin , linux-omap@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.7 154/274] drivers: net: davinci_mdio: fix potential NULL dereference in davinci_mdio_probe() Date: Mon, 8 Jun 2020 19:04:07 -0400 Message-Id: <20200608230607.3361041-154-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wei Yongjun [ Upstream commit e00edb4efbbc07425441a3be2aa87abaf5800d96 ] platform_get_resource() may fail and return NULL, so we should better check it's return value to avoid a NULL pointer dereference since devm_ioremap() does not check input parameters for null. This is detected by Coccinelle semantic patch. @@ expression pdev, res, n, t, e, e1, e2; @@ res = \(platform_get_resource\|platform_get_resource_byname\)(pdev, t, n); + if (!res) + return -EINVAL; ... when != res == NULL e = devm_ioremap(e1, res->start, e2); Fixes: 03f66f067560 ("net: ethernet: ti: davinci_mdio: use devm_ioremap()") Signed-off-by: Wei Yongjun Reviewed-by: Grygorii Strashko Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/ti/davinci_mdio.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/ethernet/ti/davinci_mdio.c b/drivers/net/ethernet/ti/davinci_mdio.c index 38b7f6d35759..702fdc393da0 100644 --- a/drivers/net/ethernet/ti/davinci_mdio.c +++ b/drivers/net/ethernet/ti/davinci_mdio.c @@ -397,6 +397,8 @@ static int davinci_mdio_probe(struct platform_device *pdev) data->dev = dev; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) + return -EINVAL; data->regs = devm_ioremap(dev, res->start, resource_size(res)); if (!data->regs) return -ENOMEM; -- 2.25.1