Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2232295pxp; Mon, 21 Mar 2022 14:29:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZYl30hI7ilIzX7HB/FCshjNDIxqk+VHVS49wTJbkYnT0ES5zOzi++zlE8EGAz91Tj/qAE X-Received: by 2002:a17:902:f54f:b0:154:5686:7616 with SMTP id h15-20020a170902f54f00b0015456867616mr7282583plf.125.1647898195032; Mon, 21 Mar 2022 14:29:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1647898195; cv=pass; d=google.com; s=arc-20160816; b=EF/lW00jheI+qfvTzKMRyf9ObnPHprmFivW/bZuyJZraSKJqilMBCzkZD0vNV7+yjZ D/OHPgjVGBXpNVUpqzDgHiNHuSBrB/Q9oEQZSxHTXhIOcGbcISf+auWtb6woJzJlLOWq 6UP3+bBranrRBxJ4lLY6grw8JKdD6prRiO85qPLIKoxLQgECLIc/xVo1eSGDKDvI7kO/ 4VtH5VeOu/VXgOq9LbFxFokot9zmV29+viFEovJGjW5x8Cny/uVag6xrH8a/Susnrxiw 3nFx8vggreBTch2r3E3oRaSpIFINTRUWfAl0QgmGGN9RV/nDdpwJQ+1xE8xzRtqKB0x1 dICw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=MsDCulQpcD9m/DjdIMrWLb4wVyFFnpMan6I3dPox3VE=; b=WHjf+uIS/IefrwAIv4tibJVJ3NAwW5rglkmx9TFjDiz7SajHe78E3s7YzKN1GzwLhy V8QlG8SesRr+3WptYKYzeURaM9TGKvPOVNAtaR1fZ8T6XNSRDksMmo9Zgp8ilgFM+kiz /4x2Ux4qlX5+3f8PuoYa6ww3fk5P+i09mPXgz83dZ7V1RTU961tqMg5tSiiQ7dIMMc3i cIYhbhGdnn92oA1oxdLn/ZCHUKlHYpkG9ePqPRqDFgwJ2F91IgnEroqe5UUM3vho0y1Z GwAhJsOMETIYL9K1iYY6vmFX/tbcksDGL0AI3katgvtfmNNwaf39rXnRaWyoeP0q+KU7 VNlQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=LrF4lwrs; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id a21-20020a170902ee9500b00153b2d16439si9173422pld.65.2022.03.21.14.29.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 14:29:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=LrF4lwrs; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2B8124B434; Mon, 21 Mar 2022 14:09:44 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346002AbiCUL0Z (ORCPT + 99 others); Mon, 21 Mar 2022 07:26:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238787AbiCUL0X (ORCPT ); Mon, 21 Mar 2022 07:26:23 -0400 Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-eopbgr50049.outbound.protection.outlook.com [40.107.5.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69CA62D1C8; Mon, 21 Mar 2022 04:24:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hn0XP0UhfcgNMbb5nGVYD4vxzVr9fCMgDqtRWeIRZ6HiARG02wNdMhzT8+VCssMnVCdsSqNU35uQeN3OR+apSUzhvJ4l2ceC9AyoDyK+PYNMeXLpojK7r2b9Zf+x10UsgQmwsHSLzKQNJhVUzle6r+HvxzNfbCpzJKavd0coHKM3sONKNLdGTGR7SXvflNQPJ1geEPdFtaHwflZs9LDGQ+0Z8kzo7bAikUrEu7Mqm/hz7QjTXv0//nfosclaC8h/Ocv9zvxl71b5JFXqcTCfZYxa888do48h8BJRuAyVt0S1NEviPdGljK5BjqsJ3HXZBLijHRRcxAz46+24yFQ5ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=MsDCulQpcD9m/DjdIMrWLb4wVyFFnpMan6I3dPox3VE=; b=NcCeyJBKKJgk9KGwy4JkZsn/palIjWA95Wif7KUmupynnXSb+pknOxuYkxdpHiXwaikKFHoArSi3I6MX8SmN5s3zXeP4Cedcx2YJiIxvQgTMp2cmDq/JsYqWBdmMPhneEZjsKfJAqzKrcULWCAsNrtSPBR3STj49zJhFA6e3wbRp5HY8SX7lJNv8wDY7kuc50SkyZZQjmzhEe5cX1a/D10bzuO8LLOjnX/GtyjBJj4JZ6XkGFAPzPLsKYM+gFi7IJeZ/09Lp2Bj4fJRRWnFMs0lyhhu5XEOqrxssxtg5n9bSGfppIQR7DcLZDBbCO38esVyIt2MKbGBF2FuRjEjDTA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MsDCulQpcD9m/DjdIMrWLb4wVyFFnpMan6I3dPox3VE=; b=LrF4lwrsSlRf1ngbjabLlqtjzgu5rTO/7vemow2YYZNgU8l7hxeyU39PTIEEDsGUyTHUMRB6Wmtyp5UbxivvZQbkWRq4lgKV+HHOdfhhIkMnlCENE5+VzstEAeQVTKOq1MT+Ydfo7C0F9hIs9tJLamOTJcCSlPcBNny4zpIhV4c= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB8404.eurprd04.prod.outlook.com (2603:10a6:20b:3f8::7) by AS8PR04MB8514.eurprd04.prod.outlook.com (2603:10a6:20b:341::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.22; Mon, 21 Mar 2022 11:24:56 +0000 Received: from AS8PR04MB8404.eurprd04.prod.outlook.com ([fe80::6972:1f59:5d1c:e557]) by AS8PR04MB8404.eurprd04.prod.outlook.com ([fe80::6972:1f59:5d1c:e557%5]) with mapi id 15.20.5081.022; Mon, 21 Mar 2022 11:24:56 +0000 From: Sherry Sun To: gregkh@linuxfoundation.org, jirislaby@kernel.org, vabhav.sharma@nxp.com Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, linux-imx@nxp.com Subject: [PATCH] tty: serial: fsl_lpuart: fix potential bug when using both of_alias_get_id and ida_simple_get Date: Mon, 21 Mar 2022 19:22:11 +0800 Message-Id: <20220321112211.8895-1-sherry.sun@nxp.com> X-Mailer: git-send-email 2.17.1 Content-Type: text/plain X-ClientProxiedBy: SI2PR01CA0043.apcprd01.prod.exchangelabs.com (2603:1096:4:193::12) To AS8PR04MB8404.eurprd04.prod.outlook.com (2603:10a6:20b:3f8::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5f5c4db7-29fc-465a-d8dd-08da0b2d6d2d X-MS-TrafficTypeDiagnostic: AS8PR04MB8514:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EpDwiyD2wnvNpBrCk0eK6V3HiEo16lu5jk/TXeXDqwluFEcWLEt/uTNBmmm/O16xgZKPJUABTjoJJ9m2GyEgVX7grpIhzXisfPBYwvIO+CgI9VShb5odwY1T8XjbCgEfyo7L8jk9MAmD6V/AS5u6M+7FLtMbCOwNnhTH0CIoe0Aj/bhi2QBNbsfk2uom3puY3r9ZjOYdAPVr22/vXzvgzYbsvBfelOBaJFtpmZnt5uqUBMnrTkBUSN8tqmJap/j1WVnOvcBrvSL3zFYBLztLBSYchlErzQMNJktZS+1hYWu7voanUxHbFUi0aIR0yX6NhRxOQPicy+0OJGWf/zLMHezJzHfmp+BlYbmZJOsblXc6dZjRjDVUEXYqicNlsgOFkIYQKD1WpsXXI4YAEhDkKGyi2j9nvV0XQBZeOD8wRUXLk/Obr/SzsMzOb98VQKbKPIcprtHKhDp0Jm5qlAtI8+Ytws6j3XD7Zs/KxNo5t3VqhT0WarD5M0ea8kj7cGAybEhu+/tp3YhrIxDenpSp8Kd48i5bf3eGYwWi0Z7l+c9dqI6bQSxvrZKvxZoulU/pRlDIP0YLoroK72A8krKZRJXftNzC/PU02ORZRNQf8w1vfI5r8BRERmlTutDwg600H+ag6IDqN4Dq3F27okPdJ5qjBIt/YUOzsISDLvLRs8ARVii08r4P9Bc2h6okZMeo0hv7k4ZNvQqQj/aqwxZkqA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR04MB8404.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(86362001)(186003)(26005)(44832011)(83380400001)(52116002)(316002)(6506007)(6636002)(5660300002)(38350700002)(6512007)(2906002)(36756003)(66946007)(2616005)(4326008)(8676002)(66476007)(66556008)(38100700002)(6666004)(8936002)(508600001)(1076003)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?WD4H9/whvbA304O0M9lUAJ6m9CEibETWvJGPdWSAIoDkVmXQyjg6OJkIDvAH?= =?us-ascii?Q?Xz7Z3q+cJ3C5tkfFJ7F1IoAxsksyxPNmDs+yw6vu2uyvZlCGyXWSnM+p5n/4?= =?us-ascii?Q?HNaztMu7selc8/YF5YL+bUmQAsfk5jpeLugRJeqFdlyLWDQdA944/VHEFT8O?= =?us-ascii?Q?g84nkFJ+N1Ud9DluJsPK9IvWGpjcCmnLXCkbYMw25CMqJXfoJt3FfrgUUvDB?= =?us-ascii?Q?UW9+nQf1lyj7TqrX/OS272YAjg6ca0Z4V9yD/W8nNnjbeS8M5ApcR3oA6MYX?= =?us-ascii?Q?gImzBrHG10qGCTnhiqRsGrKJrYJHlgHXMI3q24/B0gWByLk7tozrB59PXWy7?= =?us-ascii?Q?O/V8SWZf2K2Ieg1Pd+nYQrY39HfuVH78HLV3+oygvvMrg9wprnR6BK/XD2/s?= =?us-ascii?Q?dPbhCWh47lq7bn5eAgEfoJr7158aKxAlMJyKP7FY6FK86bVQvElYNaLETCls?= =?us-ascii?Q?rQIaqVoROs9rNBOwumsH2wpGskDoABPpdqqkkvxKVCw2y0En5o5EmE/A/nTH?= =?us-ascii?Q?KK01k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Ifhr09VFF?= =?us-ascii?Q?Jaim4rG7XKW0NZJ8NFrjhwxqwRA6zTRJ?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5f5c4db7-29fc-465a-d8dd-08da0b2d6d2d X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8404.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Mar 2022 11:24:56.1689 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: kXmxxXNPbd4R4zeZbbhCnhAEcL+QMxQRHqeVdBH6sgczG+n2KDr2mFYR7FVwHClgtAIvUuHy3I/LgHuCZkSoiw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8514 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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 --- 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 452a015825ba..40465d23d7ad 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, @@ -276,7 +274,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 { @@ -2716,23 +2713,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; @@ -2781,10 +2773,6 @@ static int lpuart_probe(struct platform_device *pdev) failed_attach_port: failed_irq_request: 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; } @@ -2794,9 +2782,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) @@ -2926,7 +2911,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.17.1