Message ID | 1705925049-5756-1-git-send-email-michal.vokac@ysoft.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-32986-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2526156dyb; Mon, 22 Jan 2024 04:12:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IEOso3m4RNBO+E0fsoJ4rD2Vcp9kUKjvRaVGJL0H0WYbStpMPk2znvGmMPrQZq4RZVids2o X-Received: by 2002:a05:6214:2426:b0:681:57da:2345 with SMTP id gy6-20020a056214242600b0068157da2345mr5013068qvb.67.1705925537438; Mon, 22 Jan 2024 04:12:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705925537; cv=pass; d=google.com; s=arc-20160816; b=wMnJt82BUbi7Tibnc6ErLvdEVP0mliGvaDl9Y8wCsmx9/AqyEgRRLs0XPbwv217gS/ hWS3N2N71k8WZUne2LLwbtc13hBsOJO73rznBVhVEXVsaULlXaVbasgJ2jvW0iZXhK1D vN4dVmu+Hy7YnrCydcbC3CsOMPHonEb56jl0vKcjIvPvmomKhBxDUdZjdlBqAHH0YdWO v/kbwRXmjl6d0LyXGhKcA7vvHGLWG5oU3+eS4pBJkmRu6Aao7+Jz6UnovaJ+Lp2d9ova JLN5yPDjqDiHG9pP43JCHzX4PbgSsiWkxIWS/ELyIBJIPE4zMkcpZaFOMTTuYqilLmwE NFvg== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=Zemy8ZJn5fD/HAJy6AeSeL43fUsG/BaVJW5l8hEuiYo=; fh=uZUGNaNbTB4leTaWIJ4NY0WSjnrJK2yvJBZeSLh9DpQ=; b=NqbgT8RXNErMIlNu8SS6A7FYeui2E5xM7MVTrSmd5dwsUUiFfyqbDcbz40/A8b4APj 12vn3HLeIk8XcbnykgIBNoroa6ArsNODc6KdBQCSLYXGfrX39lx238/kFYzoGsijpySz +ZSPmAPMIzG4Vgvt74MY32BvJCy0I85KZdA3HUPve/Zm7dC6u3POLdMLnV7QP6GhIO6d BcnuNmUlwze6D0W1o5zXhcI8W/brnQr0+sgtrGZmoRokCSEjdRW1RAIz+Lsie6U3L/Lm YMg+H7KUpmbWxh4AthhXqN/9//f8ipe7wB9ALF/g+kYttgmlEViRoJXNtsy1s5ZUAQqT MFGw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass (test mode) header.i=@ysoft.com header.s=20160406-ysoft-com header.b=Vxsnss3X; arc=pass (i=1 spf=pass spfdomain=ysoft.com dkim=pass dkdomain=ysoft.com dmarc=pass fromdomain=ysoft.com); spf=pass (google.com: domain of linux-kernel+bounces-32986-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32986-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ysoft.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id z15-20020a0cda8f000000b006819279ed95si5379982qvj.111.2024.01.22.04.12.17 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 04:12:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32986-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ysoft.com header.s=20160406-ysoft-com header.b=Vxsnss3X; arc=pass (i=1 spf=pass spfdomain=ysoft.com dkim=pass dkdomain=ysoft.com dmarc=pass fromdomain=ysoft.com); spf=pass (google.com: domain of linux-kernel+bounces-32986-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32986-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ysoft.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 3CF491C229A1 for <ouuuleilei@gmail.com>; Mon, 22 Jan 2024 12:12:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B4C3F3BB28; Mon, 22 Jan 2024 12:12:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ysoft.com header.i=@ysoft.com header.b="Vxsnss3X" Received: from uho.ysoft.cz (uho.ysoft.cz [81.19.3.130]) (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 9ED743BB21; Mon, 22 Jan 2024 12:11:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=81.19.3.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705925518; cv=none; b=Wr269FIAXPaiIegy3wOgwq2cftxr1M8U/zVBm2d5r5uqvEfZTQMGJanACOIRQxaWJlb9+gpr0O21GvtmgtlVq97uisZ1qI358aPu115eRchoBDMAl1id+vvITxZ4/h//g1AXLpRluFmR+B/n1jGhEPhq99tmGINU8W8PT4Kyp44= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705925518; c=relaxed/simple; bh=TPVj2fxS1zs2uqfH2OqzpWSshq8vUs1z/gIbUq8u8zk=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=gH3sDj9hFC3+rr8BPOgdFe5CGH17f5imSSZGcEt5itECuYnrkRQZxYaWrPE3eUD7fxk1p4InSCC1cPw2LTHW4aTcyyZoz1yRg2ZlWnLP3Dx8sCSAx84XNQav91Xvma/JLdL5RoAg0IeLaDlfpUjXAS1m/cTZXgqBIaY5hAQEKMU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ysoft.com; spf=pass smtp.mailfrom=ysoft.com; dkim=pass (1024-bit key) header.d=ysoft.com header.i=@ysoft.com header.b=Vxsnss3X; arc=none smtp.client-ip=81.19.3.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ysoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ysoft.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ysoft.com; s=20160406-ysoft-com; t=1705925076; bh=Zemy8ZJn5fD/HAJy6AeSeL43fUsG/BaVJW5l8hEuiYo=; h=From:To:Cc:Subject:Date:From; b=Vxsnss3Xelc4d4COJPjkA/pP8rIdNLk5/pq1UjfwXrdTnCm8bxQ3sbyrBlIdp1OtJ NEs/p3pmHMCzkEAUKi1ZQzD/6c/H3DHuDlkcMz9reQAhyHTTBD3D2iHNQ4JlbSPTn9 QMBw33r5e1U9X2sDxwIQZId8Aog2Hx0rduTSRoJ0= Received: from iota-build.ysoft.local (unknown [10.1.5.151]) by uho.ysoft.cz (Postfix) with ESMTP id 59ED3A00CE; Mon, 22 Jan 2024 13:04:36 +0100 (CET) From: =?utf-8?b?TWljaGFsIFZva8OhxI0=?= <michal.vokac@ysoft.com> To: Andrew Lunn <andrew@lunn.ch>, "David S. Miller" <davem@davemloft.net>, Florian Fainelli <f.fainelli@gmail.com> Cc: Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Christian Lamparter <chunkeey@gmail.com>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, petr.benes@ysoft.com, =?utf-8?b?TWljaGFsIFZva8OhxI0=?= <michal.vokac@ysoft.com> Subject: [PATCH net] net: dsa: qca8k: fix illegal usage of GPIO Date: Mon, 22 Jan 2024 13:04:09 +0100 Message-Id: <1705925049-5756-1-git-send-email-michal.vokac@ysoft.com> X-Mailer: git-send-email 2.1.4 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788792576523442581 X-GMAIL-MSGID: 1788792576523442581 |
Series |
[net] net: dsa: qca8k: fix illegal usage of GPIO
|
|
Commit Message
Michal Vokáč
Jan. 22, 2024, 12:04 p.m. UTC
When working with GPIO, its direction must be set either when the GPIO is
requested by gpiod_get*() or later on by one of the gpiod_direction_*()
functions. Neither of this is done here which result in undefined behavior
on some systems.
As the reset GPIO is used right after it is requested here, it makes sense
to configure it as GPIOD_OUT_HIGH right away.
Fixes: a653f2f538f9 ("net: dsa: qca8k: introduce reset via gpio feature")
Signed-off-by: Michal Vokáč <michal.vokac@ysoft.com>
---
drivers/net/dsa/qca/qca8k-8xxx.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
Comments
On Mon, Jan 22, 2024 at 01:04:09PM +0100, Michal Vokáč wrote: > When working with GPIO, its direction must be set either when the GPIO is > requested by gpiod_get*() or later on by one of the gpiod_direction_*() > functions. Neither of this is done here which result in undefined behavior > on some systems. > > As the reset GPIO is used right after it is requested here, it makes sense > to configure it as GPIOD_OUT_HIGH right away. > Fixes: a653f2f538f9 ("net: dsa: qca8k: introduce reset via gpio feature") > Signed-off-by: Michal Vokáč <michal.vokac@ysoft.com> > --- > drivers/net/dsa/qca/qca8k-8xxx.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c > index 4ce68e655a63..83b19c2d7b97 100644 > --- a/drivers/net/dsa/qca/qca8k-8xxx.c > +++ b/drivers/net/dsa/qca/qca8k-8xxx.c > @@ -2037,8 +2037,7 @@ qca8k_sw_probe(struct mdio_device *mdiodev) > priv->dev = &mdiodev->dev; > priv->info = of_device_get_match_data(priv->dev); > > - priv->reset_gpio = devm_gpiod_get_optional(priv->dev, "reset", > - GPIOD_ASIS); > + priv->reset_gpio = devm_gpiod_get_optional(priv->dev, "reset", GPIOD_OUT_HIGH); > if (IS_ERR(priv->reset_gpio)) > return PTR_ERR(priv->reset_gpio); Hi Michal So the current code is: priv->reset_gpio = devm_gpiod_get_optional(priv->dev, "reset", GPIOD_ASIS); if (IS_ERR(priv->reset_gpio)) return PTR_ERR(priv->reset_gpio); if (priv->reset_gpio) { gpiod_set_value_cansleep(priv->reset_gpio, 1); /* The active low duration must be greater than 10 ms * and checkpatch.pl wants 20 ms. */ msleep(20); gpiod_set_value_cansleep(priv->reset_gpio, 0); } Doesn't your change make the gpiod_set_value_cansleep() pointless? Please extend your patch to remove it, maybe extending the comment a little. Please also make sure what v2 Is Cc: to the qca8k Maintainers. Andrew --- pw-bot: cr
On 24. 01. 24 0:07, Andrew Lunn wrote: > On Mon, Jan 22, 2024 at 01:04:09PM +0100, Michal Vokáč wrote: >> When working with GPIO, its direction must be set either when the GPIO is >> requested by gpiod_get*() or later on by one of the gpiod_direction_*() >> functions. Neither of this is done here which result in undefined behavior >> on some systems. >> >> As the reset GPIO is used right after it is requested here, it makes sense >> to configure it as GPIOD_OUT_HIGH right away. >> Fixes: a653f2f538f9 ("net: dsa: qca8k: introduce reset via gpio feature") >> Signed-off-by: Michal Vokáč <michal.vokac@ysoft.com> >> --- >> drivers/net/dsa/qca/qca8k-8xxx.c | 3 +-- >> 1 file changed, 1 insertion(+), 2 deletions(-) >> >> diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c >> index 4ce68e655a63..83b19c2d7b97 100644 >> --- a/drivers/net/dsa/qca/qca8k-8xxx.c >> +++ b/drivers/net/dsa/qca/qca8k-8xxx.c >> @@ -2037,8 +2037,7 @@ qca8k_sw_probe(struct mdio_device *mdiodev) >> priv->dev = &mdiodev->dev; >> priv->info = of_device_get_match_data(priv->dev); >> >> - priv->reset_gpio = devm_gpiod_get_optional(priv->dev, "reset", >> - GPIOD_ASIS); >> + priv->reset_gpio = devm_gpiod_get_optional(priv->dev, "reset", GPIOD_OUT_HIGH); >> if (IS_ERR(priv->reset_gpio)) >> return PTR_ERR(priv->reset_gpio); > > Hi Michal > > So the current code is: > > priv->reset_gpio = devm_gpiod_get_optional(priv->dev, "reset", > GPIOD_ASIS); > if (IS_ERR(priv->reset_gpio)) > return PTR_ERR(priv->reset_gpio); > > if (priv->reset_gpio) { > gpiod_set_value_cansleep(priv->reset_gpio, 1); > /* The active low duration must be greater than 10 ms > * and checkpatch.pl wants 20 ms. > */ > msleep(20); > gpiod_set_value_cansleep(priv->reset_gpio, 0); > } > > Doesn't your change make the gpiod_set_value_cansleep() pointless? > > Please extend your patch to remove it, maybe extending the comment a > little. Hi Andrew, I agree, in this case the call to gpiod_set_value(1) is now pointless. I will remove it and describe the change. > Please also make sure what v2 Is Cc: to the qca8k Maintainers. I wonder who do you mean by qca8k maintainers? There is no one explicitly stated as a qca8k driver maintainer in MAINTAINERS file. I admit that there is couple of people listed in get_maintainer output as authors/commit signers that I have not Cc'd. I have added them to the Cc list now and will do in the v2 as well. Thanks for the comments! Michal
> I wonder who do you mean by qca8k maintainers? There is no one explicitly > stated as a qca8k driver maintainer in MAINTAINERS file. > > I admit that there is couple of people listed in get_maintainer output > as authors/commit signers that I have not Cc'd. get_maintainer gives you both the formal Maintainers, and the de-facto maintainers due to actually working on the driver. I would expect Christian Marangi to get Cc:ed, and maybe others. > I have added them to the Cc list now and will do in the v2 as well. Thanks Andrew
diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c index 4ce68e655a63..83b19c2d7b97 100644 --- a/drivers/net/dsa/qca/qca8k-8xxx.c +++ b/drivers/net/dsa/qca/qca8k-8xxx.c @@ -2037,8 +2037,7 @@ qca8k_sw_probe(struct mdio_device *mdiodev) priv->dev = &mdiodev->dev; priv->info = of_device_get_match_data(priv->dev); - priv->reset_gpio = devm_gpiod_get_optional(priv->dev, "reset", - GPIOD_ASIS); + priv->reset_gpio = devm_gpiod_get_optional(priv->dev, "reset", GPIOD_OUT_HIGH); if (IS_ERR(priv->reset_gpio)) return PTR_ERR(priv->reset_gpio);