Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp750616rdb; Sun, 18 Feb 2024 09:59:50 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW0OS69aa0LOVtsBizYTdEf+9c5LfobGB0uoLOfR7jHHgXdZYCa6lBfjS5CQD9AHfteBTA4c5iBH1BrkWXbHiMI7UNnJAeqMN/c0XnpHQ== X-Google-Smtp-Source: AGHT+IG7B7mPJI33N7XDlDkRv1iMKHJsUKPj0EHmhgpke3Jop4WT7DSJYBJgX5VQl7K9D0UCgvqO X-Received: by 2002:a17:906:b191:b0:a3e:9ad2:b555 with SMTP id w17-20020a170906b19100b00a3e9ad2b555mr229656ejy.24.1708279190009; Sun, 18 Feb 2024 09:59:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708279189; cv=pass; d=google.com; s=arc-20160816; b=DbJTgqVSQ1IKsojyv5AtWJAomiIfust1DLEvR3O69+pN8ReJ6WKwjQAG/3v/B6c6qz 8xlryTjllxY0aB07jIepB2Gjc1/CZgqYjQMUr9UNcJ0IF/NznD2lshPcDiK92sG6oU9S PMNXm3Gj7SNKFdGGxVeECKUNuogsFlH4IAyHyS8G6TJuoy6N8lpbg49g1Suq9hFg5psd NoDuTb2oRRZpe+7UfJ6Tl5bll5BcgN7ISWmion9xYBUwCRi3WEnvctJv20XC0wXWNgOu Lui8THPlR4xXWS/4c9Ze4oQ6B2rFJxzAhmaFm7hAgQYDwinuUcyv+ILr2okO7TmwhpUs wcIw== ARC-Message-Signature: i=2; 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=tSthOcPbqRkluhLCMuiccARQ1lDOVWq7SgcjGERpCCI=; fh=dgTgHN/uiEFlUFktTBiHczNaqeE9DIkNk0NX2YvmyDk=; b=LaLFWN0QUCWeejXUcN/16FMGJ9FJ079IRnhEBYRFvuaDs/RywwXfblr/kdd4bL2POa RIE2gjIBVduHsDZngZYtcvJARyFNROqfrCt3KTf+DagYUmTbr8SJw6XT8K3UbbyCqFfV 8fi4zUxVSIrsEzCQIADaF90ZAlEEc4D4LIh6zC6+boFiaTrBJpJxcxI1m5m67+cyTO8R HXm3xVRf0v8u0JUvBn6ic5qXwVy/gsCtvME5PThZusFzhuoZrBozMLgHoNk/1yREeUk3 hQRapQxLroKPGMUSraJEkVNFdVYy2OGvYyeGfENLAnyTeS6sYoncUdr0ZSWMX3B0CzCc br7w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Hz3mcp9q; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-70470-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70470-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ss13-20020a170907038d00b00a3da146a5desi1836162ejb.990.2024.02.18.09.59.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 09:59:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70470-linux.lists.archive=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=@linuxfoundation.org header.s=korg header.b=Hz3mcp9q; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-70470-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70470-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.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 B43441F21930 for ; Sun, 18 Feb 2024 17:59:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2F3296F06D; Sun, 18 Feb 2024 17:59:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Hz3mcp9q" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 335E329401; Sun, 18 Feb 2024 17:59:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708279181; cv=none; b=RfKzqOTrZAsalqpZ0Kl8cZ8Em58HaqcFgGkKDN4BoYMjWiNrEc5gRkhAl19Mws0BMKcs7JqSTBDE1UKOnSBbTrTv0vcKa/4cS3dmGx7GQH2kbLEABG5hlbwpfpP7cxeFpXeHZO0GKQtbIdx2UYg6AAizQne+JiJer5KEfNBM/Y8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708279181; c=relaxed/simple; bh=sGnaOwL737S+kRj7YV7UEO53mnW/ESMniXC/a9CnV8Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EBAo18ljt1bMSxbPUwEZaLAi4nTq7WrjlDrJp+SCGYLQL66pNcht+0npALNLA2yJewCvfQgJtsoouHxpGotNH7RvJ5Aleypbr40JzVeHaOJPypdcKfXxfQv+SB6/Qy7/EsGvTnkK1H/8HTcz0aF0e6wmXuyXnLhI+aZ9gxvxEnw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Hz3mcp9q; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59104C433C7; Sun, 18 Feb 2024 17:59:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708279180; bh=sGnaOwL737S+kRj7YV7UEO53mnW/ESMniXC/a9CnV8Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Hz3mcp9qSGs0/vs+7b46eQwzPMyH7me2NEclwq7Wiz2p9z57WO3U4SDfq9zRiZ+4s eoHxL1rOcOjw4VzA94cyB8z646+hIPr7LaxxquJl3itnZam2hF6F+0NGjZ82vZArC9 gZoGWHEa9RflQ6vJeet7wg30LHWBfa/PeWrkRZlg= Date: Sun, 18 Feb 2024 18:59:37 +0100 From: Greg Kroah-Hartman To: Bartosz Golaszewski Cc: Patrice Chotard , Jiri Slaby , Dan Carpenter , Linus Walleij , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Bartosz Golaszewski Subject: Re: [PATCH] serial: st-asc: don't get/put GPIOs in atomic context Message-ID: <2024021851-amniotic-trimester-89af@gregkh> References: <20240214092438.10785-1-brgl@bgdev.pl> 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: <20240214092438.10785-1-brgl@bgdev.pl> On Wed, Feb 14, 2024 at 10:24:38AM +0100, Bartosz Golaszewski wrote: > From: Bartosz Golaszewski > > Since commit 1f2bcb8c8ccd ("gpio: protect the descriptor label with > SRCU") gpiod_set_consumer_name() calls synchronize_srcu() which led to > a "sleeping in atomic context" smatch warning. > > This function (along with gpiod_get/put() and all other GPIO APIs apart > from gpiod_get/set_value() and gpiod_direction_input/output()) should > have never been called with a spinlock taken. We're only fixing this now > as GPIOLIB has been rebuilt to use SRCU for access serialization which > uncovered this problem. > > Move the calls to gpiod_get/put() outside the spinlock critical section. > > Reported-by: Dan Carpenter > Closes: https://lore.kernel.org/linux-gpio/deee1438-efc1-47c4-8d80-0ab2cf01d60a@moroto.mountain/ > Signed-off-by: Bartosz Golaszewski > --- > drivers/tty/serial/st-asc.c | 40 ++++++++++++++++++++----------------- > 1 file changed, 22 insertions(+), 18 deletions(-) > > diff --git a/drivers/tty/serial/st-asc.c b/drivers/tty/serial/st-asc.c > index bbb5595d7e24..52a20277df98 100644 > --- a/drivers/tty/serial/st-asc.c > +++ b/drivers/tty/serial/st-asc.c > @@ -467,6 +467,7 @@ static void asc_set_termios(struct uart_port *port, struct ktermios *termios, > struct asc_port *ascport = to_asc_port(port); > struct gpio_desc *gpiod; > unsigned int baud; > + bool manual_rts; > u32 ctrl_val; > tcflag_t cflag; > unsigned long flags; > @@ -517,26 +518,12 @@ static void asc_set_termios(struct uart_port *port, struct ktermios *termios, > ctrl_val |= ASC_CTL_CTSENABLE; > > /* If flow-control selected, stop handling RTS manually */ > - if (ascport->rts) { > - devm_gpiod_put(port->dev, ascport->rts); > - ascport->rts = NULL; > - > - pinctrl_select_state(ascport->pinctrl, > - ascport->states[DEFAULT]); > - } > + if (ascport->rts) > + manual_rts = false; > } else { > /* If flow-control disabled, it's safe to handle RTS manually */ > - if (!ascport->rts && ascport->states[NO_HW_FLOWCTRL]) { > - pinctrl_select_state(ascport->pinctrl, > - ascport->states[NO_HW_FLOWCTRL]); > - > - gpiod = devm_gpiod_get(port->dev, "rts", GPIOD_OUT_LOW); > - if (!IS_ERR(gpiod)) { > - gpiod_set_consumer_name(gpiod, > - port->dev->of_node->name); > - ascport->rts = gpiod; > - } > - } > + if (!ascport->rts && ascport->states[NO_HW_FLOWCTRL]) > + manual_rts = true; > } > > if ((baud < 19200) && !ascport->force_m1) { > @@ -595,6 +582,23 @@ static void asc_set_termios(struct uart_port *port, struct ktermios *termios, > asc_out(port, ASC_CTL, (ctrl_val | ASC_CTL_RUN)); > > uart_port_unlock_irqrestore(port, flags); > + > + if (manual_rts) { > + pinctrl_select_state(ascport->pinctrl, > + ascport->states[NO_HW_FLOWCTRL]); > + > + gpiod = devm_gpiod_get(port->dev, "rts", GPIOD_OUT_LOW); > + if (!IS_ERR(gpiod)) { > + gpiod_set_consumer_name(gpiod, > + port->dev->of_node->name); > + ascport->rts = gpiod; > + } else { > + devm_gpiod_put(port->dev, ascport->rts); > + ascport->rts = NULL; > + pinctrl_select_state(ascport->pinctrl, > + ascport->states[DEFAULT]); > + } > + } > } The 0-day bot rightly points out that manual_rts could be uninitialized by this change, so I'm dropping it from my tree. Please fix up and resend. thanks, greg k-h