Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2371909rdd; Fri, 12 Jan 2024 07:33:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IEQ6Xq+t89Y8jwutujV+BTRyD2IidZrFliNSWAxMxcHr4z/TQ8V0XJ3PnpdvJUhYgE5oLMg X-Received: by 2002:a17:906:18e1:b0:a26:c595:62c0 with SMTP id e1-20020a17090618e100b00a26c59562c0mr378997ejf.47.1705073589720; Fri, 12 Jan 2024 07:33:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705073589; cv=none; d=google.com; s=arc-20160816; b=t6rdPh4RZdnYHusFf5EWFAuBKXkc+02RXSZS6aTdJLiuyYIvBPU2+0VkywC0VLmyQH uxSs8RjwkAKjoR0v7P7RRuwgyCBkdLwmuPB5HQo+RjoRTX8wMOHSb73kFdatFhF2gtX5 dH1Y7t+U5nqPsOZLrwGNxBcvomB3WPd0+j5kTJKMKsaeTP5hh4Z1jPSYmNhWGWjx7f5B tBzW7YIOKVj6x2lbszh7K4hzYON206F3BlhlG0QYXBXGXxjA8xIeYC1Eexjai/0uduHa ZQ8Q6Rm9ozmfquaGazPKlJi6oyHFO3BeTJMAqb8cDfH3OjrLCN7NMxEHAx3p/4ozN46A zCiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=85qADMULPEZDkA2EsspL4/DXh5uWHSumVah5xCfPd2c=; fh=W/phKB3JP0/LYyzfdqzVVR5UJfdSdLy5J6y0BLPHY40=; b=gE3fW7z8BdiAOpV66OeSuxeQIJW78x1NMbi05GSak6B9U4qGqoZqJ1vsGtJdeJibOd W+D7p/090FCylnjm1Y/zwUn6WLtsw3bb/Ly5jsjHJ3CVCYe6ihGJxRnZTuXN4TcnAPJW V0ejuvAWmj1mYkWQLkLNw+Jp1T+Izk5HKkdmBZa4qTTSXVgkv8tiZ9zkiK/VhXLBHfih jreD+9IekZKVa3pmn4xj+kxy6+N73LBQbBmxgtwqFMGZCG18vYqL2DhZ//oXYf+nw6C5 nJVUkMkgQvMwJBfOlcTC+VliqsuckM6/saeWYRe45f5uqp6VlGxLsADXfr+eyeJA//UC iJaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=KOsCe2Ix; spf=pass (google.com: domain of linux-kernel+bounces-24804-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24804-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lunn.ch Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id g5-20020a170906c18500b00a27c7dc1f6esi1491714ejz.477.2024.01.12.07.33.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 07:33:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24804-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=KOsCe2Ix; spf=pass (google.com: domain of linux-kernel+bounces-24804-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24804-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lunn.ch Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 740DD1F23EED for ; Fri, 12 Jan 2024 15:33:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 272BB7317B; Fri, 12 Jan 2024 15:32:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="KOsCe2Ix" Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0313373178; Fri, 12 Jan 2024 15:32:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=85qADMULPEZDkA2EsspL4/DXh5uWHSumVah5xCfPd2c=; b=KOsCe2IxmDGDyoQUwKb0peqW9f kaGwxaLExgF6q2FNPLMh6Nkz8r3GYtx5n8L+6cNdYF23OTcBQGHASobbH3TAl0Gk3Ng/eAtyhyzyz rEHJS9UHfOXg3SWSOTmXt7wWw0SuHWEWBZc/pFqqlmimPtCer+21e2e5dmH1goS93QyQ=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1rOJW2-0055MK-GA; Fri, 12 Jan 2024 16:32:14 +0100 Date: Fri, 12 Jan 2024 16:32:14 +0100 From: Andrew Lunn To: Kunwu Chan Cc: hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, f.fainelli@gmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net] net: phy: Fix possible NULL pointer dereference issues caused by phy_attached_info_irq Message-ID: <627c9558-04df-43a6-b6e4-a13f24a8bc1d@lunn.ch> References: <20240112095724.154197-1-chentao@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240112095724.154197-1-chentao@kylinos.cn> On Fri, Jan 12, 2024 at 05:57:24PM +0800, Kunwu Chan wrote: > kasprintf() returns a pointer to dynamically allocated memory > which can be NULL upon failure. Ensure the allocation was successful > by checking the pointer validity. > > Fixes: e27f178793de ("net: phy: Added IRQ print to phylink_bringup_phy()") > Signed-off-by: Kunwu Chan > --- > drivers/net/phy/phy_device.c | 3 +++ > drivers/net/phy/phylink.c | 2 ++ > 2 files changed, 5 insertions(+) > > diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c > index 3611ea64875e..10fa99d957c0 100644 > --- a/drivers/net/phy/phy_device.c > +++ b/drivers/net/phy/phy_device.c > @@ -1299,6 +1299,9 @@ void phy_attached_print(struct phy_device *phydev, const char *fmt, ...) > const char *unbound = phydev->drv ? "" : "[unbound] "; > char *irq_str = phy_attached_info_irq(phydev); > > + if (!irq_str) > + return; > + > if (!fmt) { > phydev_info(phydev, ATTACHED_FMT "\n", unbound, > phydev_name(phydev), irq_str); This part looks O.K. > diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c > index ed0b4ccaa6a6..db0a545c9468 100644 > --- a/drivers/net/phy/phylink.c > +++ b/drivers/net/phy/phylink.c > @@ -1884,6 +1884,8 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy, > phy->phy_link_change = phylink_phy_change; > > irq_str = phy_attached_info_irq(phy); > + if (!irq_str) > + return -ENOMEM; Here, i would just skip the print and continue with the reset of the function. The print is just useful information, its not a big problem if its not printed. However, if this function does not complete, the network interface is likely to be dead. Andrew