Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3564363pxb; Mon, 24 Jan 2022 12:19:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJxn0GlpLfSCiu7+xYNqn8Cp0s7hONQtDplRwbXKHXQfBhc4kzWPPwQ5qXjBuyb4mwIRtm1a X-Received: by 2002:a17:903:32c8:b0:14b:1902:2d71 with SMTP id i8-20020a17090332c800b0014b19022d71mr15677037plr.23.1643055476925; Mon, 24 Jan 2022 12:17:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643055476; cv=none; d=google.com; s=arc-20160816; b=AB6V9edmXUAPwmcLPRaPSoiubC5BPwHaAWYYLTSTTtoh1JsSKDj/1ZjjULm1yTwNeE g4oT6R9P5IDel76hJeOjKnL90xrIG8aSNRMcy8+Y4PxoFgXQpvjnVMQusuEk+kYg0HfB 3xxJLJmhxU+WKVTeT4qzpLTNVJVg6SYFPyfWRF2VvtKUiyOd6USdHOpamssy40QGcjRF XHfW37IwuR1MexA17QODsXarkOWZ/tv4KznkTbH9hGMmDvXxiox8wyOcbQCUMfudJgjr z28w8hyqzma/emSt5r3IdTjlNXHLNR1OxO2hgdW0ljF0I9M6CefT49Z8s8O5hcxlUBDB lO2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2SS3CeHfpBOUAuayOzGs3PXvMymA8rMT9psgNOA2HEk=; b=0XNknp20hv91y6WTiqODjtjsOtFPjgqnWnOvMQkB76/Ge/F+Z1QqCOAdtwT8w2WFfy n1AFK4734wNDDkpSVTqeekPJpMUcxKnUyA968irxIcPt5WHIctbaHzmySKXUikW2XVmg kydhMANx8BeuX+2xd0ChAoMqf+3ERoPw6K8ldOlcvBsPQhyd/YkrwYzY2MVDPg6XbZ5T D4XINlb4wWh033xYBAdvDJgMgG9MGky7PZzpHoVDhTsD+YuHq0J4U1RfLhX1eQrV8ZAK D+HB3jVPB5kR2DasAFJNYaqiajRXIzMfXJzyAVPiWunEbGXMEI54DzBPG6Y2lmjdHM8w FYxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ENFfhVJx; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h20si13106499pfn.59.2022.01.24.12.17.42; Mon, 24 Jan 2022 12:17:56 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=ENFfhVJx; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345141AbiAXTVd (ORCPT + 99 others); Mon, 24 Jan 2022 14:21:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239966AbiAXTNU (ORCPT ); Mon, 24 Jan 2022 14:13:20 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DCDDC06174E; Mon, 24 Jan 2022 11:05:24 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5D036B8122C; Mon, 24 Jan 2022 19:05:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87773C340E5; Mon, 24 Jan 2022 19:05:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643051122; bh=stK8Y7QMLRFNEDBUeM2Pagi3Dg0w4T++8SxV+gFMA0Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ENFfhVJx0TLykLMPdmKoczKx2022t5Gr6z614/bJ2z0RJgw9eVa8XBvfTcR1Z7rHQ iAxJThvGIDVchrifONlNqvXd0XjafKedHiWkhNDrbre5HbNL3xcFFzgdvTkwzCmuRW rgXNd70PKMNzF8rD+GIfYd7AOQ8xcoJxUrbkGxRU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiasheng Jiang , "David S. Miller" , Sasha Levin Subject: [PATCH 4.14 061/186] fsl/fman: Check for null pointer after calling devm_ioremap Date: Mon, 24 Jan 2022 19:42:16 +0100 Message-Id: <20220124183939.086302861@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183937.101330125@linuxfoundation.org> References: <20220124183937.101330125@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiasheng Jiang [ Upstream commit d5a73ec96cc57cf67e51b12820fc2354e7ca46f8 ] As the possible failure of the allocation, the devm_ioremap() may return NULL pointer. Take tgec_initialization() as an example. If allocation fails, the params->base_addr will be NULL pointer and will be assigned to tgec->regs in tgec_config(). Then it will cause the dereference of NULL pointer in set_mac_address(), which is called by tgec_init(). Therefore, it should be better to add the sanity check after the calling of the devm_ioremap(). Fixes: 3933961682a3 ("fsl/fman: Add FMan MAC driver") Signed-off-by: Jiasheng Jiang Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/freescale/fman/mac.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/freescale/fman/mac.c b/drivers/net/ethernet/freescale/fman/mac.c index 387eb4a88b723..3221a54202638 100644 --- a/drivers/net/ethernet/freescale/fman/mac.c +++ b/drivers/net/ethernet/freescale/fman/mac.c @@ -96,14 +96,17 @@ static void mac_exception(void *handle, enum fman_mac_exceptions ex) __func__, ex); } -static void set_fman_mac_params(struct mac_device *mac_dev, - struct fman_mac_params *params) +static int set_fman_mac_params(struct mac_device *mac_dev, + struct fman_mac_params *params) { struct mac_priv_s *priv = mac_dev->priv; params->base_addr = (typeof(params->base_addr)) devm_ioremap(priv->dev, mac_dev->res->start, resource_size(mac_dev->res)); + if (!params->base_addr) + return -ENOMEM; + memcpy(¶ms->addr, mac_dev->addr, sizeof(mac_dev->addr)); params->max_speed = priv->max_speed; params->phy_if = priv->phy_if; @@ -114,6 +117,8 @@ static void set_fman_mac_params(struct mac_device *mac_dev, params->event_cb = mac_exception; params->dev_id = mac_dev; params->internal_phy_node = priv->internal_phy_node; + + return 0; } static int tgec_initialization(struct mac_device *mac_dev) @@ -125,7 +130,9 @@ static int tgec_initialization(struct mac_device *mac_dev) priv = mac_dev->priv; - set_fman_mac_params(mac_dev, ¶ms); + err = set_fman_mac_params(mac_dev, ¶ms); + if (err) + goto _return; mac_dev->fman_mac = tgec_config(¶ms); if (!mac_dev->fman_mac) { @@ -171,7 +178,9 @@ static int dtsec_initialization(struct mac_device *mac_dev) priv = mac_dev->priv; - set_fman_mac_params(mac_dev, ¶ms); + err = set_fman_mac_params(mac_dev, ¶ms); + if (err) + goto _return; mac_dev->fman_mac = dtsec_config(¶ms); if (!mac_dev->fman_mac) { @@ -220,7 +229,9 @@ static int memac_initialization(struct mac_device *mac_dev) priv = mac_dev->priv; - set_fman_mac_params(mac_dev, ¶ms); + err = set_fman_mac_params(mac_dev, ¶ms); + if (err) + goto _return; if (priv->max_speed == SPEED_10000) params.phy_if = PHY_INTERFACE_MODE_XGMII; -- 2.34.1