Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp339437rdb; Thu, 8 Feb 2024 07:26:34 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWHxFGv/bOkcrZS88Gwz02S/4AncmsPoQ7Q8PizTZI5KAU6+yuiUJlYREhlYLM0A+VSoAkeThW6iGz5BiyWtVVPYKEVjwlU8DPNZvRQZA== X-Google-Smtp-Source: AGHT+IHYotAIYvL/Nol0urntRyMX+qGpzrME7q3/K6seEeH0jIYtnQDz3Uyb4OmVuNrG5IqEgIG+ X-Received: by 2002:a05:622a:19a0:b0:42c:760:8b29 with SMTP id u32-20020a05622a19a000b0042c07608b29mr10634005qtc.54.1707405993988; Thu, 08 Feb 2024 07:26:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707405993; cv=pass; d=google.com; s=arc-20160816; b=ySKk30oamhELFFIhC9qpGRGnTPbED4recHMJ41OJx+DUTPBofRVfxCyjJr/vDnC91b 7G1B10PnH3ipTViMv93YaPw79xObz9xRqKjxZ83F8IWhFKFCGWxOmRREhyRCPT2Tcm+H Sy21U9A0rXo4UKyre6DOm2He3XEkcYPxG5IiNnSRDQIvMmytb26g1Bw6SvcUMrwmmbqI 8zhBobGkifQvkCdciPN5vvfmFzfAPLHrv0CyfC7B5qJ8obDzf1OjsXrN7H6Ge91isNVr DK3hs7gSafUBZe6o5+3k84fW7XBKQ8eTBV/zHdKJ5ky46hMV6EzvH7P6LbXt3Hw3U1kS s09g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=subject:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :cc:to:from:date:dkim-signature; bh=jog1i33uHRXEYtwEaKRBf0ivRlCDI/h7IaGamPhR7RI=; fh=bDYaMKFCyjNn2EwPNQVMjBWBT+6aZnt29gLAVBYsdJQ=; b=qrPWf/GDiQMRh8Uncr/MGhA4ilM8YcioYCbki1+ec/CiLI6if9LLO0yDXaB2Qs+zdN qBxRX877/4LucCJ8qJik/FFi54LPZTLrC8gGdxY51hpnBjHCkED/fBnJ6GMbUqfa5vAZ tkAE8qPpNMUcqzj4RkRaihWFMdIPRNb0+ItOE6LSM399R0BbXxUQSslkWKgz6i92FqBn CjmbVYLwksdgLZj9u6GcAlP1JHcamGADwa+WxuEirS9QsaZYHXMSKA1SSjBhFue6whfT m5YKXMrB2RiZONM56MeFibL0/CSt9j13EfrZnUwXZmr/+oWRG0zQMHuXX9JNtCz0J8Fg 2fsA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@hugovil.com header.s=x header.b=tBo8WICt; arc=pass (i=1 spf=pass spfdomain=hugovil.com dkim=pass dkdomain=hugovil.com); spf=pass (google.com: domain of linux-kernel+bounces-58282-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58282-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCVkQhVtlzCq6/LTb9j1z3Pvkixy6l7u4W3ZU7PamF9/znycVR/DM8SJPPvJYewdlGpZ2+ZWbmdwnys8WGyCLl8Q0qONwXwb1IGON3pElA== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 8-20020ac85708000000b0042bf9317920si188281qtw.775.2024.02.08.07.26.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 07:26:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58282-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@hugovil.com header.s=x header.b=tBo8WICt; arc=pass (i=1 spf=pass spfdomain=hugovil.com dkim=pass dkdomain=hugovil.com); spf=pass (google.com: domain of linux-kernel+bounces-58282-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58282-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id BA1791C222DF for ; Thu, 8 Feb 2024 15:26:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7FA147C099; Thu, 8 Feb 2024 15:26:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b="tBo8WICt" Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) (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 CC4DF7B3EA; Thu, 8 Feb 2024 15:26:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.120.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707405986; cv=none; b=PqxsvyfOT//VhttZAx9JddA68dEhAZtmjAGyO3eNR8Ksy6/EksGAbizHY7djAzz8ZN8Y86bA+rRcrUgJuj30xvJlgtxkJWF+9tEBVCRbuCyZXxjytWAVRH0jzUsBr5l+Wq5EwLQ+pENjSFNEayeBCXyoBPAC2E4eooVz3ueRvDk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707405986; c=relaxed/simple; bh=rGHq7lYWXIk7fsacp3KMVuL/mWPQFX1MbTYCRSGEr7g=; h=Date:From:To:Cc:Message-Id:In-Reply-To:References:Mime-Version: Content-Type:Subject; b=ep1KRhQzSK64UdV4gVzamQWnotaGsFvPHyLGNzIcRYAJalnKgYCUSdVyXHFcQFG9ZnpzJerPYZw0SmXaXc2nJtybIPWOAtc2/ipFIWlyo6eAk6XvRRyIMV5368EYiT2XwJaeINBroTwBFAioqAU3M/wIJX6PYKzA1nmGo7PejAg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hugovil.com; spf=pass smtp.mailfrom=hugovil.com; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b=tBo8WICt; arc=none smtp.client-ip=162.243.120.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hugovil.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hugovil.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:Mime-Version:Message-Id:Cc:To:From :Date:subject:date:message-id:reply-to; bh=jog1i33uHRXEYtwEaKRBf0ivRlCDI/h7IaGamPhR7RI=; b=tBo8WICt9IR9C8q9WTvXB48s87 sTxPlhAXoYLL6ZkKLFowRd6vuqCLE+Ns4eNlfjYEsNS6u+9Baa6b2NwUbg4kCVhRxsyLPPzRyPYuU zx/femYu6Nn62kqsMmKe55Cu1GRYQa36aj6OQrlcSjKXReaFKenBfU3AdE2/kL6PfyBU=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:52262 helo=pettiford) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1rY6I2-0001xf-H1; Thu, 08 Feb 2024 10:26:15 -0500 Date: Thu, 8 Feb 2024 10:26:13 -0500 From: Hugo Villeneuve To: Hugo Villeneuve Cc: gregkh@linuxfoundation.org, jirislaby@kernel.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Hugo Villeneuve Message-Id: <20240208102613.887945859e48f3b2d9519385@hugovil.com> In-Reply-To: <20240206214208.2141067-4-hugo@hugovil.com> References: <20240206214208.2141067-1-hugo@hugovil.com> <20240206214208.2141067-4-hugo@hugovil.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Level: X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * -0.0 T_SCC_BODY_TEXT_LINE No description available. * -3.3 NICE_REPLY_A Looks like a legit reply (A) Subject: Re: [PATCH 3/4] serial: sc16is7xx: split into core and I2C/SPI parts (sc16is7xx_lines) X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) On Tue, 6 Feb 2024 16:42:07 -0500 Hugo Villeneuve wrote: > From: Hugo Villeneuve > > Before, sc16is7xx_lines was checked for a free (zero) bit first, and then > later it was set only if UART port registration succeeded. > > Now that sc16is7xx_lines is shared for the I2C and SPI drivers, make sure > it is reserved and modified atomically, and use a new variable to hold the > status of UART port regisration. > > Remove need to check for previous port registration in sc16is7xx_remove(), > because if sc16is7xx_probe() succeeded, we are guaranteed to have > successfully registered both ports. > > Signed-off-by: Hugo Villeneuve > --- > drivers/tty/serial/sc16is7xx.c | 19 ++++++++++++------- > 1 file changed, 12 insertions(+), 7 deletions(-) > > diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c > index 5b53c88b7133..5073ebfc45bf 100644 > --- a/drivers/tty/serial/sc16is7xx.c > +++ b/drivers/tty/serial/sc16is7xx.c > @@ -1468,6 +1468,7 @@ int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype, > u32 uartclk = 0; > int i, ret; > struct sc16is7xx_port *s; > + bool port_registered[SC16IS7XX_MAX_PORTS]; > > for (i = 0; i < devtype->nr_uart; i++) > if (IS_ERR(regmaps[i])) > @@ -1533,8 +1534,10 @@ int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype, > SC16IS7XX_IOCONTROL_SRESET_BIT); > > for (i = 0; i < devtype->nr_uart; ++i) { > - s->p[i].port.line = find_first_zero_bit(sc16is7xx_lines, > - SC16IS7XX_MAX_DEVS); > + port_registered[i] = false; I just realised that this will not work. All port_registered[] members need to be initialized before entering the loop. I will add this (for V2) before the loop: memset(port_registered, 0, sizeof(port_registered)); Hugo Villeneuve > + > + s->p[i].port.line = find_and_set_bit(sc16is7xx_lines, > + SC16IS7XX_MAX_DEVS); > if (s->p[i].port.line >= SC16IS7XX_MAX_DEVS) { > ret = -ERANGE; > goto out_ports; > @@ -1584,7 +1587,7 @@ int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype, > if (ret) > goto out_ports; > > - set_bit(s->p[i].port.line, sc16is7xx_lines); > + port_registered[i] = true; > > /* Enable EFR */ > sc16is7xx_port_write(&s->p[i].port, SC16IS7XX_LCR_REG, > @@ -1642,9 +1645,11 @@ int sc16is7xx_probe(struct device *dev, const struct sc16is7xx_devtype *devtype, > #endif > > out_ports: > - for (i = 0; i < devtype->nr_uart; i++) > - if (test_and_clear_bit(s->p[i].port.line, sc16is7xx_lines)) > + for (i = 0; i < devtype->nr_uart; i++) { > + clear_bit(s->p[i].port.line, sc16is7xx_lines); > + if (port_registered[i]) > uart_remove_one_port(&sc16is7xx_uart, &s->p[i].port); > + } > > kthread_stop(s->kworker_task); > > @@ -1667,8 +1672,8 @@ void sc16is7xx_remove(struct device *dev) > > for (i = 0; i < s->devtype->nr_uart; i++) { > kthread_cancel_delayed_work_sync(&s->p[i].ms_work); > - if (test_and_clear_bit(s->p[i].port.line, sc16is7xx_lines)) > - uart_remove_one_port(&sc16is7xx_uart, &s->p[i].port); > + clear_bit(s->p[i].port.line, sc16is7xx_lines); > + uart_remove_one_port(&sc16is7xx_uart, &s->p[i].port); > sc16is7xx_power(&s->p[i].port, 0); > } > > -- > 2.39.2 > >