From patchwork Mon Aug 17 15:15:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 266009 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FFBBC433E3 for ; Mon, 17 Aug 2020 19:23:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 17F77204EC for ; Mon, 17 Aug 2020 19:23:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597692191; bh=EXzeOTHPIzPxT19jkvKZyyanh+VKXO8I23xTbKj1mVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=z2lL9VWBhCU4RRymj/Wx7BY8F/jQZMjXAglCaBeOAih0lNuSX4MLUCSEDd2f8zrJd uhtF+2nJ6Ga5M9Fxq0JQUCIi7kNdsWTIO5RlC/4XWo1ZNXqikeI45yXQu0AthzYurW Ipzw+TSeicZUh0stFEWh6/A2pbZ5uw24bs/4heqg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730730AbgHQTXJ (ORCPT ); Mon, 17 Aug 2020 15:23:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:41830 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730460AbgHQPfO (ORCPT ); Mon, 17 Aug 2020 11:35:14 -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 5DD752173E; Mon, 17 Aug 2020 15:35:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597678514; bh=EXzeOTHPIzPxT19jkvKZyyanh+VKXO8I23xTbKj1mVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f2lUx186VrACE1qCP2bIjyyeJUi9JUg36ciFOs+pwRbr0Fjdt6TtBxhfPkg2sDzkR Z0ntr8sUA7RtanHy+sef2gYeVlLou07GSiZnR77alPbhsvgAF09YQmht3KOJK9Rfj1 dfW3e5JmBPXQ5A7B0HFd5U/7fsR9BuUkoRORv99o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Florinel Iordache , "David S. Miller" , Sasha Levin Subject: [PATCH 5.8 361/464] fsl/fman: fix dereference null return value Date: Mon, 17 Aug 2020 17:15:14 +0200 Message-Id: <20200817143851.065581371@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143833.737102804@linuxfoundation.org> References: <20200817143833.737102804@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Florinel Iordache [ Upstream commit 0572054617f32670abab4b4e89a876954d54b704 ] Check before using returned value to avoid dereferencing null pointer. Fixes: 18a6c85fcc78 ("fsl/fman: Add FMan Port Support") Signed-off-by: Florinel Iordache Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/freescale/fman/fman_port.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/freescale/fman/fman_port.c b/drivers/net/ethernet/freescale/fman/fman_port.c index 87b26f063cc82..c27df153f8959 100644 --- a/drivers/net/ethernet/freescale/fman/fman_port.c +++ b/drivers/net/ethernet/freescale/fman/fman_port.c @@ -1767,6 +1767,7 @@ static int fman_port_probe(struct platform_device *of_dev) struct fman_port *port; struct fman *fman; struct device_node *fm_node, *port_node; + struct platform_device *fm_pdev; struct resource res; struct resource *dev_res; u32 val; @@ -1791,8 +1792,14 @@ static int fman_port_probe(struct platform_device *of_dev) goto return_err; } - fman = dev_get_drvdata(&of_find_device_by_node(fm_node)->dev); + fm_pdev = of_find_device_by_node(fm_node); of_node_put(fm_node); + if (!fm_pdev) { + err = -EINVAL; + goto return_err; + } + + fman = dev_get_drvdata(&fm_pdev->dev); if (!fman) { err = -EINVAL; goto return_err;