Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp632177iog; Mon, 13 Jun 2022 09:31:31 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ulyDCongTL9hlOxjLG5gxKrwPZDKOJ+3rJV5O8SM9wX5JCRimD1hYdQzLIoh6XMIEsGgx8 X-Received: by 2002:a17:903:2483:b0:168:c4c3:e895 with SMTP id p3-20020a170903248300b00168c4c3e895mr491294plw.0.1655137891390; Mon, 13 Jun 2022 09:31:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655137891; cv=none; d=google.com; s=arc-20160816; b=nLqEHNqKLgrIteCgFsFoL40n/OEpnkSqBDpsd5cLvmgUHtY875Qx21YHYsjoaj8bsk 4WVwSYxkdRM8YhE4J9EmkCxeKHA0y+JD3Og6WWCyCUYAihXtiWEhtxJEnMMnlZfq25oV Hy6vf0uFJDN7QZerSzwN+h9Ve9SeaFYvzHyURAH3SeenRYWiJX2iKA77vEXMuJ++4OMk uzk6du5AgJxs4/xsf9u/ciPeT55815HGqdJ+gfvUUgK+WlSgTxqBQztk+YBRkFnNCBG0 aDQz8+9FgYGzYQhu8+QxS7g5kd6opncQh8aMD9P/h4VdxtCy/Oe2R5bKGNgljsX2wIJ5 Dj8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4IFmYp6DQLQ+eOy+mSVrczKx+aRV8wHl3z+XIR0Cx4M=; b=yM75BRDLvRfIBk8nvMGZ2u/ZXX7gH16vbyPxz+H7NwrPCYdKTsms9M2a1KdQWsBp3r gFUH8l85YE7FLZ8GQoSptnCjYFbNKuIag4cPoRwZUQ2lHICXsvOEG4qt9HfgpaDj0UJc Q2oOVpAGvwsnq5A7GixthOiqq+rBF1C2BUTxsl1ZtAwsB3PxIigBs1cYWD2Pkc5wM27N T0lZC1E/EHVRP6qEd62fL0Pny3frjcTPpUghTFZsJ4zMyb3E9eUvMneNqSfix90bcRxf ac7rckv+NkHByKTAEk1tcYvNyOJR3ZiIbJlQuJ8MbkHexV0rQRqoe9pOz0x0FapQ50RP yqTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=d1SCA2PY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mw18-20020a17090b4d1200b001e06828a394si45558pjb.27.2022.06.13.09.31.17; Mon, 13 Jun 2022 09:31:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=d1SCA2PY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353174AbiFMMwM (ORCPT + 99 others); Mon, 13 Jun 2022 08:52:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355359AbiFMMu1 (ORCPT ); Mon, 13 Jun 2022 08:50:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F99C633BA; Mon, 13 Jun 2022 04:12:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CA6CA608C3; Mon, 13 Jun 2022 11:12:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7D52C36AFF; Mon, 13 Jun 2022 11:12:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655118733; bh=ZCUTqRz7IFjMLmE0HtszpJPuvsXC2mGDJlhmF6y6hP4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d1SCA2PYXpHxKrrO+Dni7m68UoOcuo9NJsNwlHMDIzhLCF5f7tX0NKI7RfO5Nb9X9 y1PseaJtLFcxdLifjus7b5+1Hr7M54Tbm0F1ig+t2ekaXaSxr9vme0nBOIyMPdiyaG G1Y97YExercKeoz1tlMF3R4S6GR+HIyT2BYuXcw4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sherry Sun , Sasha Levin Subject: [PATCH 5.15 010/247] tty: serial: fsl_lpuart: fix potential bug when using both of_alias_get_id and ida_simple_get Date: Mon, 13 Jun 2022 12:08:32 +0200 Message-Id: <20220613094923.233237547@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094922.843438024@linuxfoundation.org> References: <20220613094922.843438024@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sherry Sun [ Upstream commit f398e0aa325c61fa20903833a5b534ecb8e6e418 ] Now fsl_lpuart driver use both of_alias_get_id() and ida_simple_get() in .probe(), which has the potential bug. For example, when remove the lpuart7 alias in dts, of_alias_get_id() will return error, then call ida_simple_get() to allocate the id 0 for lpuart7, this may confilct with the lpuart4 which has alias 0. aliases { ... serial0 = &lpuart4; serial1 = &lpuart5; serial2 = &lpuart6; serial3 = &lpuart7; } So remove the ida_simple_get() in .probe(), return an error directly when calling of_alias_get_id() fails, which is consistent with other uart drivers behavior. Fixes: 3bc3206e1c0f ("serial: fsl_lpuart: Remove the alias node dependence") Signed-off-by: Sherry Sun Link: https://lore.kernel.org/r/20220321112211.8895-1-sherry.sun@nxp.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/fsl_lpuart.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c index 33e5eba6ff04..481107fdd69b 100644 --- a/drivers/tty/serial/fsl_lpuart.c +++ b/drivers/tty/serial/fsl_lpuart.c @@ -239,8 +239,6 @@ /* IMX lpuart has four extra unused regs located at the beginning */ #define IMX_REG_OFF 0x10 -static DEFINE_IDA(fsl_lpuart_ida); - enum lpuart_type { VF610_LPUART, LS1021A_LPUART, @@ -275,7 +273,6 @@ struct lpuart_port { int rx_dma_rng_buf_len; unsigned int dma_tx_nents; wait_queue_head_t dma_wait; - bool id_allocated; }; struct lpuart_soc_data { @@ -2703,23 +2700,18 @@ static int lpuart_probe(struct platform_device *pdev) ret = of_alias_get_id(np, "serial"); if (ret < 0) { - ret = ida_simple_get(&fsl_lpuart_ida, 0, UART_NR, GFP_KERNEL); - if (ret < 0) { - dev_err(&pdev->dev, "port line is full, add device failed\n"); - return ret; - } - sport->id_allocated = true; + dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret); + return ret; } if (ret >= ARRAY_SIZE(lpuart_ports)) { dev_err(&pdev->dev, "serial%d out of range\n", ret); - ret = -EINVAL; - goto failed_out_of_range; + return -EINVAL; } sport->port.line = ret; ret = lpuart_enable_clks(sport); if (ret) - goto failed_clock_enable; + return ret; sport->port.uartclk = lpuart_get_baud_clk_rate(sport); lpuart_ports[sport->port.line] = sport; @@ -2767,10 +2759,6 @@ static int lpuart_probe(struct platform_device *pdev) uart_remove_one_port(&lpuart_reg, &sport->port); failed_attach_port: lpuart_disable_clks(sport); -failed_clock_enable: -failed_out_of_range: - if (sport->id_allocated) - ida_simple_remove(&fsl_lpuart_ida, sport->port.line); return ret; } @@ -2780,9 +2768,6 @@ static int lpuart_remove(struct platform_device *pdev) uart_remove_one_port(&lpuart_reg, &sport->port); - if (sport->id_allocated) - ida_simple_remove(&fsl_lpuart_ida, sport->port.line); - lpuart_disable_clks(sport); if (sport->dma_tx_chan) @@ -2912,7 +2897,6 @@ static int __init lpuart_serial_init(void) static void __exit lpuart_serial_exit(void) { - ida_destroy(&fsl_lpuart_ida); platform_driver_unregister(&lpuart_driver); uart_unregister_driver(&lpuart_reg); } -- 2.35.1