Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3601085pxb; Mon, 24 Jan 2022 13:14:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJzH88vDiRynXKS7kxzY8HIuBg63qKIuHobu7Q056SlWXjd6Tjqd6c+5c93CFGOhzdLdas+7 X-Received: by 2002:a65:6114:: with SMTP id z20mr13279421pgu.124.1643058877545; Mon, 24 Jan 2022 13:14:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643058877; cv=none; d=google.com; s=arc-20160816; b=MZXGFphUlHaJniVkeobwKVqFqMlK/Z3eHKQtrQ3JOqtS91oZbfDMp0dAZRRDvfzWGT fuYfD1SBA/2XDboGEQcYnZy1xfgU9NsieJe77AldOW6pSVvLTcwUfVFxJz4m6998xDKH R9npvdXEXNKvuePXR+J3MDQ40IoHLiJfc+0E6OB1GntoFLUuMXBgcS6egGFMQ6R3ZVEh GYXwL2BVHEUaHQoxyDfv3thnTPBoOfa81hslOHk+yO0DNgmVCMnZvGiG/my7dxYD0swO 6iv8j6/8SyGpCb3nx0WwJc/lYfLLFRmenUfodnTJg90N33LMn+rgl8qHlrE0b9GK0VDX knrw== 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=lI4ADmQnOpK/LUyYTDTTa3akwkXlAdX4oyIfOV2T89U=; b=uyfVLiVOK3Qq/fh4a2ZbBV38Ln4vobPzr1CdA7uj/T6kHQSbJSbLSkZGFoCVka8PM1 1a2M6SL+0RJxdAnagqnp4uE7V7VKN1mikLHamgLlWuYmATFGvnquczKkW9Pot32XkUpU ZOhrt6lTwVCaepYQXRSp+89mYGJmOEgSmIx7bDmqlLoOX+g8S2hvaxzhKn0XigIX/c2A 9VGFWLPOEzph5OlhAhMqlAZCIjmIV6kY3GA5pNafEQK9b3lOOjtVkVVzAj+bZ51O0VXs Fr8099GacKj3TVFnu6yzpsaAt+3CMm4Bl3wdGLIc+w7nJMg4BTdUS4OmYuoxz7UWnV+2 DTyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FwhDtKpk; 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 q32si9707249pgb.361.2022.01.24.13.14.22; Mon, 24 Jan 2022 13:14:37 -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=FwhDtKpk; 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 S1390104AbiAXUow (ORCPT + 99 others); Mon, 24 Jan 2022 15:44:52 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:51592 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382576AbiAXUZz (ORCPT ); Mon, 24 Jan 2022 15:25:55 -0500 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 dfw.source.kernel.org (Postfix) with ESMTPS id 061B961506; Mon, 24 Jan 2022 20:25:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4C06C340E5; Mon, 24 Jan 2022 20:25:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643055954; bh=GkT1JKyiWTehfmwWT0NQjNXlQrkt2/3NKwSy1Olvcsk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FwhDtKpkj1bnn8NLlh2Em17DTr1LVYNd4tXjhLBQG7GO5bS0f4dRjLXHR36B0LFrv aH1SawMLMxJNzF3m8j6vJSsoZSR2bkuVdgVPNnzFW5Q8lk26LuXmIgfy0MpTBqn4IN VXL0+8KliC9ZeUyCqD8B0y5lpRIVj14up7+m45xQ= 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 5.15 320/846] fsl/fman: Check for null pointer after calling devm_ioremap Date: Mon, 24 Jan 2022 19:37:17 +0100 Message-Id: <20220124184111.940892689@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@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 d9fc5c456bf3e..39ae965cd4f64 100644 --- a/drivers/net/ethernet/freescale/fman/mac.c +++ b/drivers/net/ethernet/freescale/fman/mac.c @@ -94,14 +94,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 = mac_dev->phy_if; @@ -112,6 +115,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) @@ -123,7 +128,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) { @@ -169,7 +176,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) { @@ -218,7 +227,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