Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1138558pxa; Thu, 20 Aug 2020 03:41:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQKc0KEOPhep/5uWKDdFBfVayFFn1INwIVcOoj1yy2edpBViWQsicLfAZc22on0lYUtJGJ X-Received: by 2002:a50:d942:: with SMTP id u2mr2376520edj.0.1597920106266; Thu, 20 Aug 2020 03:41:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597920106; cv=none; d=google.com; s=arc-20160816; b=DNGN4j1eX4IXdHj2qyFD4MFpx23iTWWXq4Es9AtDM71VZOTtIlWrdLmlZYyv7Wju0l NnB/8p35WyHbZdookc8TJOhE3VgGy8ERllil1DLmqfO8qAbVvqUuwYXzLAPd7Jd0lIsG 7KzQ6ZStm+sKDMstDEQOiFfGxu9nv8iyqqA/gQxDcix1ZPRPonYcnqD/9cRvv2C0gV/f fCpVSpl7jm08m5l3Pd6q2q5IPCsWzT5IyRT10KHBtpTqg0iVNy39S20NTaXmFiUUQtzC Fc2t5wbhm2Yw/21T8zn5TV82aDioVnz00kbThM2rMlgWmXaRB5IWu5UhEr5dmq0p6tkR 6MUw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JgWhqqIQFYjYFYHrgoVUIfLoVvRjLdBNpJ0qyQjT7xM=; b=xXtMBNOES/7G972Eiaxgl+gGVl9VC9VHVJt3jhijyQTAg3ntzjK7FLtGVHIVHPbcWF 5gJ3aCnOG6ur8JL2/pI86i7BWuasS9c7kCZt9BFrUsQmaUHYRVmFiJYaY1O2YRYp3hSl v/y3+3fLNY/o8EcHUMK2rPhE00+l9glkEVBnf46Pz44n9Dqw0SjiIPNBpYy6ym3/3B8T 5rk9iIwgQMZq8ZfFQ2AfzO3+lf+5de83gqMM/ShNsxurt86zQBGgHH6rmLtXniron3RN 1H4odrPcbDQ5MOYFyYr+evMkFEA5pDT4ytv1jV/HLP7BL57DCvNzrKQgkiR06rAmHTab ZIbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Y+D1O7dJ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a7si943000ejg.108.2020.08.20.03.41.22; Thu, 20 Aug 2020 03:41:46 -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=Y+D1O7dJ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728747AbgHTKkr (ORCPT + 99 others); Thu, 20 Aug 2020 06:40:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:38130 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731297AbgHTKRJ (ORCPT ); Thu, 20 Aug 2020 06:17:09 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8A0B7206DA; Thu, 20 Aug 2020 10:17:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597918629; bh=u6dXuoPiaENmRNqE8B4CVCL/ojOT6YVvOGiNB+YjyjU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y+D1O7dJWMwZmXv9cKHWn7cVHxGbuAVOrdXV9b45KPbdBzSLWOXocC8fM8atT7D6F JgBnPdyLP4uqGiyAhN5ZGnRMGAna2YBrbVAWwms7AtfahuWD6btvYLUYfUtOkw81fe 5lFKEAg7pJKs3h6rG2f3OO76quQVeaSYSeiRPY3Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wei Yongjun , "David S. Miller" , Sasha Levin Subject: [PATCH 4.4 002/149] net: phy: mdio-bcm-unimac: fix potential NULL dereference in unimac_mdio_probe() Date: Thu, 20 Aug 2020 11:21:19 +0200 Message-Id: <20200820092125.808314571@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820092125.688850368@linuxfoundation.org> References: <20200820092125.688850368@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 297a6961ffb8ff4dc66c9fbf53b924bd1dda05d5 ] platform_get_resource() may fail and return NULL, so we should better check it's return value to avoid a NULL pointer dereference a bit later in the code. This is detected by Coccinelle semantic patch. @@ expression pdev, res, n, t, e, e1, e2; @@ res = platform_get_resource(pdev, t, n); + if (!res) + return -EINVAL; ... when != res == NULL e = devm_ioremap(e1, res->start, e2); Signed-off-by: Wei Yongjun Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/phy/mdio-bcm-unimac.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/phy/mdio-bcm-unimac.c b/drivers/net/phy/mdio-bcm-unimac.c index 4bde5e728fe0a..fd8692b477c96 100644 --- a/drivers/net/phy/mdio-bcm-unimac.c +++ b/drivers/net/phy/mdio-bcm-unimac.c @@ -177,6 +177,8 @@ static int unimac_mdio_probe(struct platform_device *pdev) return -ENOMEM; r = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!r) + return -EINVAL; /* Just ioremap, as this MDIO block is usually integrated into an * Ethernet MAC controller register range -- 2.25.1