Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp531624rdh; Wed, 14 Feb 2024 04:29:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUPY1njk47KCWgxiORoq28l5y/6kcusOkF90km/cYld+NQ+fQNw38bf53MF95azvEmC0j8aVIBPO2eTszibomk2OV6nVaoH0l3Gm/pZZA== X-Google-Smtp-Source: AGHT+IF2L06ntEZSP+4fAOVQgFUU+CgGSLCUyiaE/dkgn64fo3wFrXpWVcI710YOMhIni1ir6CAP X-Received: by 2002:a05:6358:7e94:b0:176:9e87:412c with SMTP id o20-20020a0563587e9400b001769e87412cmr2809566rwn.7.1707913795772; Wed, 14 Feb 2024 04:29:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707913795; cv=pass; d=google.com; s=arc-20160816; b=EmLSMAHv4bsxzjQTSR3kYIJ3jvx6F1iCpfb9GoOtS7ue+8ehk1l1NJGY+H0tP6U3aN zhprAw0UzfRRjOAuEplXSPThKG4mr8dNrwY1xopFW2mL9JBenlIE/UV8tZZR1MLUiGy2 xmqLLTzSYqIL4ECBlITJnhfxQymQGqSN+1qq/kltlivJF4VIm/+7Y+7qAKBUSna5EIpS tiHDeGfMvFyzFgqf/AZ7plQ2bZaCawyLUx92PMr93z5Qt6fj815eMOp2pqDa/lPelrKY 1SsPlPXQDsOQQy51hrUto5zU4QAm4t8/1Mz7PsVsMVuc9vxWcVKPlFOZ7VjOTR/Ec3gd FN1A== 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=9/VawfV3/1Tia6h+B0jEdvM/GHLbKTQGOHVDuUn/OA0=; fh=v38PZBwPeyKuQ/zOgEq0KWE/30E3m8eN+EVPe9rUQko=; b=Q8WtdobHdYzQFx5tT0n+CGgZx6I4o7+wwIrkhf1oAlw92X1fSRvknLC7EeJq580eqo BqWhWApoEiG3V7sJ03QRCrEu21YmT6iDOqz5ARZqD1DoDw2chzvxzqO6MSQAbtJh/S/m o3NIuF2be7C3G2DyI2e3aDSbBpQFC+qM2/2mBKcTo15wGfB/vxAyO/7/IG04lm70sgKm H1PHKWhzPleNwT4uDh9hOgKiPIiU05nDDZhc7IgSNYLYfIruKNb5w7gPP2wOwwE4Cmgb wlEw+GyJwtE4Wjgr58l9ZGcO4xWITJ49nFSFaheQ5BnSK1a/WAWpD1+c8NmJ4M83TWOF uISQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=Rh6Ct7nc; arc=pass (i=1 dkim=pass dkdomain=bgdev-pl.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-64952-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64952-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCUEslk6nVzZ5O+N1NSygZZ6V+s3K1cUpp04DzvZNy8/ApWVmoanc6vnK8o0kZlKuCXrPKYV8HhV5ODIB3cqQs1BKhnPPFtF40VUc1yAjg== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z185-20020a6333c2000000b005dbdce9d103si3553004pgz.563.2024.02.14.04.29.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 04:29:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64952-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=Rh6Ct7nc; arc=pass (i=1 dkim=pass dkdomain=bgdev-pl.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-64952-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64952-linux.lists.archive=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id DB3FA287DAD for ; Wed, 14 Feb 2024 09:24:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DE23F12B6A; Wed, 14 Feb 2024 09:24:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="Rh6Ct7nc" Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7562A125B8 for ; Wed, 14 Feb 2024 09:24:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707902692; cv=none; b=JFnqxlGzNZlaWK0eBdaLD7dS8pEE0Ujl4Rwj8nWOhcPXtapCzW845zUzpbLGmic6kJXHHpMrM7eRF9bvP1wk9fWSe+lu3/yXZTb7icFj4H4zyhGoDFtNFLUYHkexp49iG+vkP3RKh8ax7y+BmSbe33Z9QpN9Tm13wCtaRQpGNzg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707902692; c=relaxed/simple; bh=/m6rCOBVM9runoz3Pj1rAUMrYscnZqle0dzyZA0rr6k=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Yz2++hmHDS3/B4A6ba8AQW2Ked/BLSGeg/1v0WKozHMoBIUSfVUNjJXqL7DfkytpPAZuDU6EKu34SLM1Bt+cMh7CVmTSeYnIA3NMqshBg/3mazgrlWnDm1yXyeLapdg8BC0agbxCP36K5QdoAbYb7IXcaHEKxHPC5p4YaT5xY2o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=Rh6Ct7nc; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-33cda3dfa06so936972f8f.3 for ; Wed, 14 Feb 2024 01:24:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707902689; x=1708507489; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=9/VawfV3/1Tia6h+B0jEdvM/GHLbKTQGOHVDuUn/OA0=; b=Rh6Ct7ncm7/Be0NMnTpj3kdIgh0Cmni6Npau+yreSgJANWc13Vrbf59qIGhf1FPKX7 NFYqTH8PdHWNhKNWMd4WveEv2DaDBN8Tuv1zTCGdv/MKdWjzgJ4OLya8Dfz3XEHJ58NQ BGOpvL2pSdxM9ElkGTVs5Kd6iO7Gz00HohcFsDcHx+Gozb7HZJ7fZwmrcBOkCCU+s3Iv 3BVSm+0b2xx6diLIoXbVsvPDxUUeNXf3buMrgj5PM+qEAQleJxHiCpRISayHb8YckSB4 wzYBgFRzD4LF4dFoskTQsoEfI9KWZ+rhuH3u+lHt8Q5TwJc/6jhK8/aPcrGZvjOv6IU+ 7pBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707902689; x=1708507489; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=9/VawfV3/1Tia6h+B0jEdvM/GHLbKTQGOHVDuUn/OA0=; b=pYb/N5mBnpO9o+m7SksJA9JuqPaZyNhsk8vcKnbvMKeWJwVq4+uj4Gd6/ffXK0ljFz 4K6q2yTF+UFcUPbRp1Q45Y95oyfWuinX4Tzp5XoK43brZvuOaCiWspbPg76Tv00FYoMB ATZOEk4dsDUvP4cT39k5vQ1VIaMFABwpbrnj265TUXNu2cwirrNoK/QB8k7ViSo83bPx gaWSGKwK7z5P/vpBlXFDV/slXi3JutrnEjJhv/5JgB6+NqQiIkvXU+qra3jY23OQF3qX lqY+8cyB3D1FR2JR1Uk78ssyPzhDTGl2KhtFGdsaRPgez/uYjyCCRqUyn1I32qqhV3aD zfgw== X-Gm-Message-State: AOJu0Yx1CMWS8Zh2APmMDzecHMpaIotDmaWVs1wzg7ZZBeSvu8USeg5Y dgQzai2zdCw+aMb5diQ7qLtRTxt5aKX32NZamwbOgZWBkemTJCYvgLMmAMlrqnw= X-Received: by 2002:adf:ee8c:0:b0:33b:4838:a23 with SMTP id b12-20020adfee8c000000b0033b48380a23mr1240259wro.29.1707902688721; Wed, 14 Feb 2024 01:24:48 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVLmtx2mrXUFZclfNkMiRaHwJMG3IjpvutXBS5vR6JlDfkSfBo9bD6f+2pWgnTMwvP4v2svAnnZOzAQ52da0GbSyhB+C0lOqG5l0wVU1ZoBTUdhko4EDoAQr7DgseP8FOXRJ1BxwAh0F/SV1Ux1mh4X9/LYJ63/LFE6v4t1JpqQFXGN5X1IoR6ntXBpf7M6xlFlF6FCkG9qE3hnCHj3rkgsA9+tghykXIqEjW0wsppsTYRmp1+Q7FJai0K5Z4ynJPC7U2/mVZUCTwtAr6WC6DkDbTc= Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:cfee:a5b6:1f9b:9c9b]) by smtp.gmail.com with ESMTPSA id ck13-20020a5d5e8d000000b0033b684d6d5csm12100905wrb.20.2024.02.14.01.24.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 01:24:48 -0800 (PST) From: Bartosz Golaszewski To: Patrice Chotard , Greg Kroah-Hartman , Jiri Slaby , Dan Carpenter , Linus Walleij Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH] serial: st-asc: don't get/put GPIOs in atomic context Date: Wed, 14 Feb 2024 10:24:38 +0100 Message-Id: <20240214092438.10785-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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]); + } + } } static const char *asc_type(struct uart_port *port) -- 2.40.1