Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2296851pxp; Mon, 21 Mar 2022 16:11:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygugOR3jwXnBjzaDFe+zG8wG8rjebuY8LUK6scaWwwme9syuj8sm0UU1QeZDyYDtFT0//b X-Received: by 2002:a63:6b81:0:b0:380:4fc1:ee7b with SMTP id g123-20020a636b81000000b003804fc1ee7bmr19867103pgc.298.1647904300933; Mon, 21 Mar 2022 16:11:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1647904300; cv=pass; d=google.com; s=arc-20160816; b=qAjEfhH2cxs0EwS4ZBYN76NdH7GrP6J4DdDoIUbCPK1WVwo65GWMTKJVbWXSLsppyI v2TAdLWsvwqXl7NREl3MkRRKkpTQ5ye9KFkZKXU9gktDP95l2VDq6e7+ZKXPsN0Lkmnj 1iYvRupp/bMdqXW7tQFGjRCmVH9BHzwH8cCBvXV+voRQ92ByFL54vcPcDes/gTp04ZBG YUYj5bKQQaI6kwQhH/Kd8thvqiV6vytOYJQ2hXfZSIvQPcbaGzJ9AfDK+UrIOf3bdwk5 /TjgbD+zIat2NWlgMAmg7KT8lyEdnN0xuEKh1a4gcoVin53zLS88+wJ1B+Wzb/e1fkso 8OUA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature; bh=R+pUVmUnDBFDrdPfiXX7u2v/2nQJhINr6rhBDssIs8w=; b=jDzraEzFemR4qjoT0liqcGPKN8C6JEFzwDBRuLqTNhj4Zj80XbmkOa5ft0rWO6ats1 VOg2R8d77GrUrjfI/03FN3JD2yHOaKqbYBvHGF7hIHQwPZFGUlUIyLpiwVcEdiEWP3P9 z4BFMF0TskATaM2RTwa2Z1ye1Sc1evdDt4Kr7be3oSZ8KZdXrnMdC8BKM9tXcDFzdYFE f43C4rectq3UbgbMV3HBVIQXEq8cRfe1aSgOjp/EyKguYPClUQYUTOT0IUIPNIErcmZ9 SZBprKkMuIEdRxBlE08BeYuvE2vHQkXgPA5m77/I8inAuEzYvG8MuBRkdXFdvuPSIA+M rqNQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=cAob8GLU; 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 gp14-20020a17090adf0e00b001bd14e030b6si541627pjb.142.2022.03.21.16.11.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 16:11:40 -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=cAob8GLU; 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 D2A0C4352D4; Mon, 21 Mar 2022 15:10:08 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347026AbiCUNfA (ORCPT + 99 others); Mon, 21 Mar 2022 09:35:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236687AbiCUNez (ORCPT ); Mon, 21 Mar 2022 09:34:55 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2051.outbound.protection.outlook.com [40.107.20.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9607F33E88; Mon, 21 Mar 2022 06:33:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Mh69Df6ZLE1rBjPoxFK5kh2suLVUUfIFoeXmnHr48/53o6IXT46KojPZb7KSQGV4SNOZyeyCXce8KgX9gnHyAOk+KU90kUrAa3rRYJSrf7OgV9UJwvX03oUYSlOu3g9dwvwJA+iYldvYzNOWLzRbkS5VdF9p6E9PE3MK73SdhxpjOUcLmKsums8gk5zsSZIyV+oJPqrREDays2clbxwQX8633H5Juxtj1imoE6at0oIArlmiiWjy+qwrH2eM3ujO3z15SaWF4QPMW58iAl/Snt90plPG8iLRlH53Us6/PDKVZM7Q2OWR+twmDioVOIqVGAo1aCVqsEcednpw2zmlNw== 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=R+pUVmUnDBFDrdPfiXX7u2v/2nQJhINr6rhBDssIs8w=; b=NetjdjDcBQZZPIsCS2Ec4fT2laSmyQibSis+vMH5ie8L/lqrYhAkquOLFIOoAAsrCnFVJMleZWMllSVi2sPGJca0EkQTlZnIPtdaLLC6LA6axmJCerEmA4u8t1VoTKVL5Lp94ZijeBvAto9OHuD++V1O2NMeTNEzp9vkFPywFHLegLOfs5l+H/QkRuTuBTT8Cs5xOeFLjIPQrVxaxsP4vZXi70k2iJUyme2cesvI+Oh+YGrmSENvjhgwtXuVb0vKtAKdofe3qFwgOtFxPaDH4+rOEtMYDdQgPraQ1b+nPnbHD6bzerLCr/ICNqXbmgl0Q//0Sd+3WhICRMkenly6dg== 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=R+pUVmUnDBFDrdPfiXX7u2v/2nQJhINr6rhBDssIs8w=; b=cAob8GLUR2Ej+ekrxPwoQ18XXpDEHsjEv3/Ed6D9PlRFsvSzGEFGNtOqf/x87bF/NuTlXWDBlhUwn7zMKXH9tMISjaeyoTd3E1/kzeDA1kscfH5e4Hfzsphw9EMkjJ0U1fQjRNW1byyTJdVw5o+CtELKUYXxzYwGikgKb+02zK0= Received: from AM9PR04MB8274.eurprd04.prod.outlook.com (2603:10a6:20b:3e8::23) by AM0PR04MB5284.eurprd04.prod.outlook.com (2603:10a6:208:cb::23) 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 13:33:24 +0000 Received: from AM9PR04MB8274.eurprd04.prod.outlook.com ([fe80::c121:7f8f:a903:ae7f]) by AM9PR04MB8274.eurprd04.prod.outlook.com ([fe80::c121:7f8f:a903:ae7f%5]) with mapi id 15.20.5081.022; Mon, 21 Mar 2022 13:33:24 +0000 From: Shenwei Wang To: Sherry Sun , "gregkh@linuxfoundation.org" , "jirislaby@kernel.org" , Vabhav Sharma CC: "linux-serial@vger.kernel.org" , "linux-kernel@vger.kernel.org" , dl-linux-imx Subject: RE: [PATCH] tty: serial: fsl_lpuart: fix potential bug when using both of_alias_get_id and ida_simple_get Thread-Topic: [PATCH] tty: serial: fsl_lpuart: fix potential bug when using both of_alias_get_id and ida_simple_get Thread-Index: AQHYPRZLkioNdXEb806mHueeH0kdlqzJ1Y2Q Date: Mon, 21 Mar 2022 13:33:24 +0000 Message-ID: References: <20220321112211.8895-1-sherry.sun@nxp.com> In-Reply-To: <20220321112211.8895-1-sherry.sun@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 223cb923-9428-4335-8643-08da0b3f5fae x-ms-traffictypediagnostic: AM0PR04MB5284: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: tQocNzTuqJhqnc3o0b4+Odpx8m/6EttDR9r3oNO7i9/eotRfng6ca4AqXHYMu9bthP8UcJcMbxMcuAbqTHaZXRR3gp1sNr9nHeXr1yyVrvOaZdBpGbHOK6EgMbaToYl4RsB2zU0s+DB6kY6KCO9TrtLWOFgQCHlKcFN1kLdPumjc4fFvSAgrweMWqBgL1kXzGFwrrDGx85/ANRSyNZ19H7Q/KRuEOZEj6at1IQggfJ3FkqnwCCSNaV3nj9kyhyguGETNIFM2wMjAKKhKuVADMsf1tBzMUDqbBOOXqcaa8AV0aqjfdHSU0tQOvdm8CO05n9uROzO5o3rBHIlEhrYFeXGAWxtVjSG1USkkkhIbbtOk/GZAUW3gMMcB4b2Ork8rP9W3VY1Ynz5LxEtYt4BNZgDmyLGc14q4EmerqSIpHahajOgkOenMf5mNT42KucJUuIYNFz5ZUBW8xaoPU11HkFgTRfqmc4y5HXY1K9NU9j//RpetSQSoZzVtKXvwDtdpyk56hpJS2GJF3SprtplbgzfOeUVyn4Cagpm7gXlYx+zHxvhoR8hhR7vGUJgyWO+1x9vFjiwAGkA7D022vuYFu06pg6ivpqEAiRzMq8nbiFwP/SO0YS32OTv9LxEUHq4ZHbJ+SPQzoqOdksIrbEeHxsuoJRQJTa8FMBmvrcxV8pV6It2OWDw8cqBSwqZWCEeYWJs9m1emw/sn8kJizTyVJQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM9PR04MB8274.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(186003)(26005)(66476007)(52536014)(8936002)(316002)(33656002)(38100700002)(44832011)(66446008)(6636002)(64756008)(8676002)(4326008)(66946007)(76116006)(5660300002)(54906003)(55016003)(66556008)(110136005)(2906002)(9686003)(38070700005)(55236004)(71200400001)(86362001)(53546011)(508600001)(122000001)(83380400001)(6506007)(7696005);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?HR0u1emeasx2+UUoSd27TN8bv+sYKWF+qhTVmNYh9BvVo5TWGWcfCQqneufF?= =?us-ascii?Q?d8pZv/K8wOf75ve7QMdfzs73iPDVfuiXznzJe6M1kIk1aTAwAYkAGe5NOW6V?= =?us-ascii?Q?f5SJYzFE2z6lBnR/CN9qSgrcSOXioq95bkcy0Vn2oIObmeGZoI4aS7g8lbyU?= =?us-ascii?Q?YxKPVcwti+wOIpj47QDK4DvYnQm0hTxsbKgKj/9sLxn47+2fokObR4wvTUvV?= =?us-ascii?Q?dJDey+y7kN3BvmHWiuZmsgmeG8oE+b+4H/Sn5G5DaZqQkTEUy3dKO5Cet4BU?= =?us-ascii?Q?dlR7mBdroinpeGk2g5kwEq5Da++Iif1Kpu+pzwylD0NxxI1HSoHCbSd2AnPL?= =?us-ascii?Q?4RwOOQgjqrX0sVeGLYqxWK9ueWVPW9jHb8llpVz1eCYUhsd+gCf/ZuQnrJsj?= =?us-ascii?Q?xZu0VYK2M1TKaZwGL5yqUnsW9ZLy2S1mZbxTOjIZYGaJrI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?Q?sMLWhsFb7RycqQ5rIM/oicMtI2oNqRpicHY5kIXX6t7AvMpLHtMiU19Nuv7q?= =?us-ascii?Q?7cRrg2awiPGcbHpBef98JHDWx7x8AiTYiN9u5iSSZdHF9pF0ET6UJ4Br4qK7?= =?us-ascii?Q?TRIVKyj2KVm7TZay2S92FkBtSMTUb3xv?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8274.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 223cb923-9428-4335-8643-08da0b3f5fae X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Mar 2022 13:33:24.1527 (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: YZyLlBUiNsP8eoQLryQQR/OhUAs2nkGm77pkOkAEiBm+xzH+IdqK95HIRgSVVBE9Rh2SqnBISB3FaNdJvD7EUQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB5284 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 > -----Original Message----- > From: Sherry Sun > Sent: Monday, March 21, 2022 6:22 AM > To: gregkh@linuxfoundation.org; jirislaby@kernel.org; Vabhav Sharma > > Cc: linux-serial@vger.kernel.org; linux-kernel@vger.kernel.org; dl-linux-= imx > > Subject: [PATCH] tty: serial: fsl_lpuart: fix potential bug when using bo= th > of_alias_get_id and ida_simple_get >=20 > 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. The behavior of ida_simple_get() is to allocate an unused alias number. Do = you see any conflict when you test? Regards, Shenwei >=20 > aliases { > ... > serial0 =3D &lpuart4; > serial1 =3D &lpuart5; > serial2 =3D &lpuart6; > serial3 =3D &lpuart7; > } >=20 > 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 beha= vior. >=20 > Fixes: 3bc3206e1c0f ("serial: fsl_lpuart: Remove the alias node dependenc= e") > Signed-off-by: Sherry Sun > --- > drivers/tty/serial/fsl_lpuart.c | 24 ++++-------------------- > 1 file changed, 4 insertions(+), 20 deletions(-) >=20 > diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpu= art.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 >=20 > -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; > }; >=20 > struct lpuart_soc_data { > @@ -2716,23 +2713,18 @@ static int lpuart_probe(struct platform_device > *pdev) >=20 > ret =3D of_alias_get_id(np, "serial"); > if (ret < 0) { > - ret =3D 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 =3D true; > + dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret); > + return ret; > } > if (ret >=3D ARRAY_SIZE(lpuart_ports)) { > dev_err(&pdev->dev, "serial%d out of range\n", ret); > - ret =3D -EINVAL; > - goto failed_out_of_range; > + return -EINVAL; > } > sport->port.line =3D ret; >=20 > ret =3D lpuart_enable_clks(sport); > if (ret) > - goto failed_clock_enable; > + return ret; > sport->port.uartclk =3D lpuart_get_baud_clk_rate(sport); >=20 > lpuart_ports[sport->port.line] =3D 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; > } >=20 > @@ -2794,9 +2782,6 @@ static int lpuart_remove(struct platform_device > *pdev) >=20 > uart_remove_one_port(&lpuart_reg, &sport->port); >=20 > - if (sport->id_allocated) > - ida_simple_remove(&fsl_lpuart_ida, sport->port.line); > - > lpuart_disable_clks(sport); >=20 > if (sport->dma_tx_chan) > @@ -2926,7 +2911,6 @@ static int __init lpuart_serial_init(void) >=20 > 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