From patchwork Sun Jan 21 19:54:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Werner X-Patchwork-Id: 189835 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2225130dyb; Sun, 21 Jan 2024 12:16:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IHU4QKSQ5rdwPhoahtlhb8NSTXU7a7yGJM/wfsNjsf7apN846AHnetN7Rk8eoRb6hFKrT6Q X-Received: by 2002:a17:907:5ca:b0:a2c:3d26:de5d with SMTP id wg10-20020a17090705ca00b00a2c3d26de5dmr1961849ejb.19.1705868185271; Sun, 21 Jan 2024 12:16:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705868185; cv=pass; d=google.com; s=arc-20160816; b=SSY+P3eo/I2qe9O2t69japzVeSwUcZtqOvcfl40TX/vyXfSKCS1vHMN165ybJJdDlQ C/ZiiYpytLqdxrOlFxlf+uBRWjhDWheuxt9E9A1xQZSqcZbewd7Jg450OH3HbODudHJL 6wK8Xg5BHgDVSWLFGgSWP9ditJl95luk3pjPeu5a6NDO+hHvv7uwn6DTOwO6hDCNvLmg zIsMLEwjR7AdHg33fGWuZnlz9+W1lo2cM5c3M/pmny1RSRc+9v0ZEZuwu+R7tqpRyTAp PRkFcrSb/XAnLisEzKevwsZ1UDE0AvVYNRuZAvsTPsYbL5FM1cItjEOBNG5dugvWzzJj VadQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-filter; bh=0fVqfQUXQoF1AGoP7P+W4Vw6CmKt77YMbNYaAqbRPvo=; fh=EW95u4Nxu1efLMnFaTYf/hfJfmSzKgtewn9i4CVxfk8=; b=fmQYniZ5yxhcjdzDb4Lf50nmS5s4o1/o8/1VfG2xVnDM/x2m2QIsR/xAcEctoYq1VY DV9h4Kjwt+yarN/ohowBA+QlLPxmvrhR+0eNToig06VewL/A8Zxqm+rZOrYg8hqY+AZZ Wl+4SjFGiiSHtdsLKZUIVPN8Eya/0iS8aO6ppTv4GYUDu7b/UkVhLfA3p/cwQ8XwFEAl 3EXzbNcBznCHIbeOsXsgZqAe3ChW2STRvTat51XQUm3KKd0cQWKg+QJubXz/jsNkcKfB WsTWY2XGm6y7IBBaGljOMJrjO3TSsRvygTj+Nbu94QgIZgxG4bdaEj2sJSAcXCSofqdj BVYQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@systec-electronic.com header.s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD header.b=LWx6bbWE; arc=pass (i=1 spf=pass spfdomain=systec-electronic.com dkim=pass dkdomain=systec-electronic.com); spf=pass (google.com: domain of linux-kernel+bounces-32176-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32176-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l2-20020a170906230200b00a2ea38f8f78si5114677eja.92.2024.01.21.12.16.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jan 2024 12:16:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32176-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@systec-electronic.com header.s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD header.b=LWx6bbWE; arc=pass (i=1 spf=pass spfdomain=systec-electronic.com dkim=pass dkdomain=systec-electronic.com); spf=pass (google.com: domain of linux-kernel+bounces-32176-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32176-ouuuleilei=gmail.com@vger.kernel.org" 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 E139E1F20F2B for ; Sun, 21 Jan 2024 20:16:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9BB9439846; Sun, 21 Jan 2024 20:15:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=systec-electronic.com header.i=@systec-electronic.com header.b="LWx6bbWE" Received: from mail.systec-electronic.com (mail.systec-electronic.com [77.220.239.22]) (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 1F8B8364A4; Sun, 21 Jan 2024 20:15:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=77.220.239.22 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705868128; cv=none; b=rAsGuWA6J3qwAajOORGvnZWHligb/RWzq7r3TzvQ5YGc8YnjHUZIl7v96lc1bdMgSxL2wGVJ1pyXIRZ+rhirEpzH/O96WIQn+nY6yZTAX1cUNg0FZMUrhK38Sr28oYVIQX9iP8mm1cpiMLSyTIG1hreqMnkIhNKOuvbtqPbNikM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705868128; c=relaxed/simple; bh=r7Mad+18u+jwnU/YF4L3AU0sCRqVEO0/VeJu9ihAzqQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CKEjnAyASMveEL72IXI4W7oPqxba3Ho8rYFHbg7izC7kw5c5FSenrGaPZpahO4hHoCxLV0OcirxUx0kIzh+dfj3sKSDf9B4fLZH5Q3zw8LX5SkXZpkxXF7ZMC7a2T4dDDiX1jSog6Akbv/Bu7z6pcoqb2n0jrdPNF3P9j0JUiu4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=systec-electronic.com; spf=pass smtp.mailfrom=systec-electronic.com; dkim=pass (2048-bit key) header.d=systec-electronic.com header.i=@systec-electronic.com header.b=LWx6bbWE; arc=none smtp.client-ip=77.220.239.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=systec-electronic.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=systec-electronic.com Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.systec-electronic.com (Postfix) with ESMTP id DD7DB941A5D0; Sun, 21 Jan 2024 21:15:15 +0100 (CET) Received: from mail.systec-electronic.com ([127.0.0.1]) by localhost (mail.systec-electronic.com [127.0.0.1]) (amavis, port 10032) with ESMTP id VBdqbwpY4LHf; Sun, 21 Jan 2024 21:15:15 +0100 (CET) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.systec-electronic.com (Postfix) with ESMTP id 3AEB7941A5CF; Sun, 21 Jan 2024 21:15:15 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.systec-electronic.com 3AEB7941A5CF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=systec-electronic.com; s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD; t=1705868115; bh=0fVqfQUXQoF1AGoP7P+W4Vw6CmKt77YMbNYaAqbRPvo=; h=From:To:Date:Message-ID:MIME-Version; b=LWx6bbWEcje9I+A8Vak4nT5lrpVEA7eRTY6tIzJf/DrH2erUNq1PdayYL08MOC9k1 nzsQhTJrAiVRn4t0xdvNyJ/DDSPHb5kGLE9EY7wSuSBwhHYc4gfUDD9b+m1t+eSYGM 9AleKwOQEOYiLHNSAK3SuUBJMl+UIBZUwegRiIaiYaHQLnnr5s26KJAH87U2zSZ1Sb xo4tLsoZX5IpE30ATIThdKh+bO3XHc4w/eZJ/DRxuO/suG0e7eE6m2pGhBeEOfn4iM xO0n2uEMuxGsJo8sYgHeVLEnqmnddKubxFAmIA5usSUgpmPQ5lBEz57rW6kZueJDik 2IRVgtpo4Z6wA== X-Virus-Scanned: amavis at systec-electronic.com Received: from mail.systec-electronic.com ([127.0.0.1]) by localhost (mail.systec-electronic.com [127.0.0.1]) (amavis, port 10026) with ESMTP id SyEDDzDb2M5X; Sun, 21 Jan 2024 21:15:15 +0100 (CET) Received: from ws-565760.systec.local (unknown [212.185.67.148]) by mail.systec-electronic.com (Postfix) with ESMTPSA id E6733940168B; Sun, 21 Jan 2024 21:15:14 +0100 (CET) From: Andre Werner To: andrew@lunn.ch, hkallweit1@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: linux@armlinux.org.uk, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Andre Werner Subject: [RFC net-next v4 1/2] net: phy: phy_device: Prevent nullptr exceptions on ISR Date: Sun, 21 Jan 2024 20:54:48 +0100 Message-ID: <20240121201511.8997-2-andre.werner@systec-electronic.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240121201511.8997-1-andre.werner@systec-electronic.com> References: <20240121201511.8997-1-andre.werner@systec-electronic.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788732438354536929 X-GMAIL-MSGID: 1788732438354536929 If phydev->irq is set unconditionally, check for valid interrupt handler or fall back to polling mode to prevent nullptr exceptions in interrupt service routine. Signed-off-by: Andre Werner Reviewed-by: Andrew Lunn Reviewed-by: Andrew Lunn --- v4: - Delete phydev_warn and comment as suggested. --- drivers/net/phy/phy_device.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 3611ea64875e..7cbe7c714177 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1413,6 +1413,11 @@ int phy_sfp_probe(struct phy_device *phydev, } EXPORT_SYMBOL(phy_sfp_probe); +static bool phy_drv_supports_irq(struct phy_driver *phydrv) +{ + return phydrv->config_intr && phydrv->handle_interrupt; +} + /** * phy_attach_direct - attach a network device to a given PHY device pointer * @dev: network device to attach @@ -1527,6 +1532,9 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, if (phydev->dev_flags & PHY_F_NO_IRQ) phydev->irq = PHY_POLL; + if (!phy_drv_supports_irq(phydev->drv) && phy_interrupt_is_valid(phydev)) + phydev->irq = PHY_POLL; + /* Port is set to PORT_TP by default and the actual PHY driver will set * it to different value depending on the PHY configuration. If we have * the generic PHY driver we can't figure it out, thus set the old @@ -2992,11 +3000,6 @@ s32 phy_get_internal_delay(struct phy_device *phydev, struct device *dev, } EXPORT_SYMBOL(phy_get_internal_delay); -static bool phy_drv_supports_irq(struct phy_driver *phydrv) -{ - return phydrv->config_intr && phydrv->handle_interrupt; -} - static int phy_led_set_brightness(struct led_classdev *led_cdev, enum led_brightness value) {