Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp3310931rdb; Tue, 6 Feb 2024 13:42:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW6SJ3Eqk69e0KRBtNI6Nr7uJDUunZDdCIgkefP1J8GXAeX5hvt/jz6P6804BFMUeJcN4oq9ltpDi3jBZlUJOEOF+Dm8hJyXPkwbKc1CQ== X-Google-Smtp-Source: AGHT+IEiyAeVI8214CcsCF22D/M7FYUkswx+ys9sN+28OJ6yQjP2fgEDvA/8PVayR9uySASwqtLL X-Received: by 2002:ac8:4788:0:b0:42b:eea9:7eb8 with SMTP id k8-20020ac84788000000b0042beea97eb8mr4287484qtq.56.1707255749609; Tue, 06 Feb 2024 13:42:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707255749; cv=pass; d=google.com; s=arc-20160816; b=vMXUCzSMcz1bDMroFSdQn3FoallM7MA2bkYxGOkIz7IaVt2RTgUa4NXrH84eCqYNwd /xDIEKlUUqVEut5QGrfFSGaHBt2gZeFXR+C0l7sCETfcmuLBmkof7vwdA7Nb9TLNGt/U xhkM7zFgKhhpvnrSyI76TqhNPPdbR5nwSYVfu6/N0CcvpcbdzBIOiUXzL3Rt1YxP82wl l8+QQ9nJ8AELhtaYTBr8pycJqrinp8lytReUkClmzkBwYFiEetG5j9Q2JiBMzPlNa4Dh 6uqZXO8yA+9Hvuh4GWBotJ0LD76C92ST6zgnvBHUv9XZJOQdrQd4xfpW0+Tbm8lAWiN3 o2eg== 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 :date:cc:to:from:dkim-signature; bh=fRQcONYVjPAuJ2IXtLvfbv954R7Ufy3J7dtvn6r3BZs=; fh=/U345oMgXANuymOJ1xNvSL8KohL/EQMrYQDn4IxVKJ4=; b=W8rji/OcT1Hoh7rVa99sKW2lE79yKdgTJQp/9FXRQ5b7/0JgkIvDcJxwxZNUEfWqmj cznlTA6ghPDavUw2AeQ3fglhdIm2YgG2lyyzooJc8OBRqkwov2ldugKye9VujQWzYZax RjheSXU1SSWscDZBR+8mVAjSwbPLdWfYE/GopVgkjJ65a2qlBULiiHdlBseCaB8BNfiC t00cp58CtIUSWoEU+nrMerfLsxmdcWtQYz6VOGZteEksoDPe8Iy8oAHac8w0JIrUrioB fSJjP4q2v+6SrGwEHQkJHInSRfdS3ubFlzft/5n+jv4xgRjh1qHEgTD8QYjNHpblouLt 0IJw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@hugovil.com header.s=x header.b="fwsW/SiH"; arc=pass (i=1 spf=pass spfdomain=hugovil.com dkim=pass dkdomain=hugovil.com); spf=pass (google.com: domain of linux-kernel+bounces-55641-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55641-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWc6uPuAHdN/5A3ssYNU4RToVlqLoV6B+0sFqCLJcarbsiqiW7XBOlYKpzebvTv8rOKG6Oi8q+k0H10KqK3g21yl8Konp4kK7WiXrrWjQ== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d14-20020ac85ace000000b0042c2e652de8si3418812qtd.335.2024.02.06.13.42.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 13:42:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55641-linux.lists.archive=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 header.i=@hugovil.com header.s=x header.b="fwsW/SiH"; arc=pass (i=1 spf=pass spfdomain=hugovil.com dkim=pass dkdomain=hugovil.com); spf=pass (google.com: domain of linux-kernel+bounces-55641-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55641-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 5DDFD1C23217 for ; Tue, 6 Feb 2024 21:42:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 971A91BC3C; Tue, 6 Feb 2024 21:42:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b="fwsW/SiH" 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 E511F1BF27; Tue, 6 Feb 2024 21:42:20 +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=1707255742; cv=none; b=BEsRG1aM7jT2oMPq891dESPJQIKEwKwqhZVapBqtg4KGyb8m1Zt9MOaqHErFmgZBtmBm7HJlm0iZovo9B+ASdNu4hXOdsyyuql9Hg0DqGMkBFK7MsA7QUsHJIyRu22GTwgxZVRhoQ84tgCTN1PgCn/rXKhC3CTnd8b4g1QBDWkc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707255742; c=relaxed/simple; bh=q9fwZBAXTcQtKBv6I5CxylABhvION6OPfRGnEWczYgM=; h=From:To:Cc:Date:Message-Id:In-Reply-To:References:MIME-Version: Subject; b=hAFDS2Zz1yS/pF95W+XQltKCpr6ym7ca1/zqap9Zs91zURURqRCE1l0dbi2VHAP0zd8ox9b7VvQLmTEYLF/T9cWkywxi6UojRcjHkOV/4du3EI9uPC6FbMB6LBsgl4DkOZml/Bw8U9UcIKS7xATthNbUJtQlfL2aTn0QbCrC9eM= 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=fwsW/SiH; 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:Date:Cc:To :From:subject:date:message-id:reply-to; bh=fRQcONYVjPAuJ2IXtLvfbv954R7Ufy3J7dtvn6r3BZs=; b=fwsW/SiHMdayWibIXMwqX98qqb /ZOySCo2eS5wf4JshM66p90SZT4ETeTQZEGXn7ueG6RaWUL/+jGMyeHsEeKcCslATc3N4nZ3KwVAr cWS25rpAKvnh7QB16RPHhvx3ZgUiTkNQrsIKEANHKFPS59DWgmpLQrPZ+qvKMc5EMNOQ=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:41434 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1rXTCs-0006XX-8A; Tue, 06 Feb 2024 16:42:19 -0500 From: Hugo Villeneuve To: gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, hugo@hugovil.com, Hugo Villeneuve Date: Tue, 6 Feb 2024 16:42:07 -0500 Message-Id: <20240206214208.2141067-4-hugo@hugovil.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240206214208.2141067-1-hugo@hugovil.com> References: <20240206214208.2141067-1-hugo@hugovil.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. Subject: [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) 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; + + 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