Message ID | 20230315105400.23426-1-sherry.sun@nxp.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2261498wrd; Wed, 15 Mar 2023 04:07:31 -0700 (PDT) X-Google-Smtp-Source: AK7set+MQOvU4KD7JbXcj6OOLeHD/OtVMqwHTXkMVb+F3H8Vhq+QYTkk2wym9NbuDThABU2pAvKG X-Received: by 2002:a05:6a20:b2a6:b0:d5:b3d1:bff9 with SMTP id ei38-20020a056a20b2a600b000d5b3d1bff9mr4117779pzb.52.1678878451391; Wed, 15 Mar 2023 04:07:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1678878451; cv=pass; d=google.com; s=arc-20160816; b=lYQFHHa8nPbG9ORbivADk01ZaxWxSqw5Vxqx3bZ1AYvNs5COFEyBPLdhCAWbS3u9SI FkCr9Et7urDwWx4YRdxrEkZPez4dSnoEK9B5fwWcps3rJHIJrR+rNNePW30tV2w2M2RU YPqmynatFHdQiuFDIVs1Ij8wdVDFL9ccIrviniqbCvlOwzdcxgamCjSCSytlljN43iQF lDtXA7V+UA+0ibGhToGL//eXOJyuxoZ/NybYFznujkhzdQuiQhpH6Fxco4GY7uDEVViU k8KIWe1ThxPwvXf3MMqSpu8MG7cWgNVOBJHdFMCAQdYJprji7i7XU5c4RYCN9xTUWaFM 6RtA== 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=xP8wSlLZUZNLfoCz/QYATrIvPkwpSUidNR5fT3E5Sto=; b=RPgQWJaIvkUWS6hkoR/Mvk1EDWngHSC/SO7rECzUQA5Uq0/tDFA1dlqgxhBHOyquJE kRwYZ9kkV9FN0XzVBP3yDX8a4FMlAj8tQDb/7yvsZoeHaaDvsJpUP4E0YfrIWaiFfqnR hBsmjKEgGVGiMkxZU3jyUlsu5qgviOSh/NqXwft1UPpnJB0x4FuEml153RDCiyMU5qiu KORfQWoZqxCEtb/fPjdtObWe77tvoxNIwZiXbppmzZOXBesFv65Dax8EWW2NIeHBX2vz jz+O9EuURgipQYSXrhEvfrbTPgdwfKgS+4pJWq1vUSpU0YqYgbwE/A76/3RhDoarP3m7 IO6A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b="ZagLTd/x"; 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:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r75-20020a632b4e000000b004fb8d2b25d2si4600177pgr.827.2023.03.15.04.07.18; Wed, 15 Mar 2023 04:07: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=@nxp.com header.s=selector2 header.b="ZagLTd/x"; 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:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231669AbjCOK5o (ORCPT <rfc822;ruipengqi7@gmail.com> + 99 others); Wed, 15 Mar 2023 06:57:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231503AbjCOK50 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 15 Mar 2023 06:57:26 -0400 Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2085.outbound.protection.outlook.com [40.107.241.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56A537FD51; Wed, 15 Mar 2023 03:57:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I2Y/SL6g+r0UWrMdAnthIV/hqqpT3XaYRZq3iXNic8kg+Ljd3eLTfUFTfqO1LNl7arjtFlAWlIzDcHfv7LN5EmHcwr6urD310+JUUpIdXSScI5kUW0ARL3M6c0HwbDF3+XmkmAUQXQdEoii/jJjiQhtohBRDXpwmzf8HMMmmWssrscE1bDeJ4VNmDRawYotzhVlMxCCaQ6b7l1m9bk+PgWHWqjHRFBz42SboeWYfzLx4vmnSIKgoycxSccCy0lF8KiHaoMuHXfXloRwGGmW4KVsEgo0lTdepfjklErXcOZql/GM+XuO9FHyKRDOhoisV37tDWUbRsXxeLaCILsXp/Q== 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=xP8wSlLZUZNLfoCz/QYATrIvPkwpSUidNR5fT3E5Sto=; b=IJx6iOFYQyfY/djZ06ohcmWHS5FktDDO1rqGs/I+RBm1jBsMIjVNaDINmIdcjxRlrIOaiR+JBL4gXTgzeKQi65NvMH6dxUeyfN3XAFTa47N73ozNvc+JOh/GHzOa3D0PrE58aDUFhzB6bo8lwqILALefcKu4D29hEuzyBwguE30t019DeFruVhTIYTzFZRW1o683S2dJIiS71QJLWbb4DIunQ1pcGrkgKSgZ+DFaNqGECNTkUQgozsB4e21K1xog0gnqZBdCS9Xttioe62XhJsirdCKKTghDB0sqa7hmZ1j0csuRUjVemJjXql8J8BF19k5p2/48SVsD+zxMH0gBzw== 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=xP8wSlLZUZNLfoCz/QYATrIvPkwpSUidNR5fT3E5Sto=; b=ZagLTd/xgh0nO4F1PtmC4ckZjlauTC6/+bFquStCAak792rL7jALZpHyABMe4QPNXgBpOWEbwwKcydEa63v8DwVLMeRFZ23Q4zLhEkuBqQOB6TkcPUbZ5M1Xop4F9jhJh4WBhM8L8M3gfZWXYxqAzM9rIAiOqc0YeFcexw9RFJw= 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 AS1PR04MB9263.eurprd04.prod.outlook.com (2603:10a6:20b:4c5::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.26; Wed, 15 Mar 2023 10:57:08 +0000 Received: from AS8PR04MB8404.eurprd04.prod.outlook.com ([fe80::3079:f55a:740e:c103]) by AS8PR04MB8404.eurprd04.prod.outlook.com ([fe80::3079:f55a:740e:c103%9]) with mapi id 15.20.6178.029; Wed, 15 Mar 2023 10:57:08 +0000 From: Sherry Sun <sherry.sun@nxp.com> To: gregkh@linuxfoundation.org, jirislaby@kernel.org, robh@kernel.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, linux-imx@nxp.com Subject: [PATCH] tty: serdev: serdev-ttyport: add devt for ctrl->dev Date: Wed, 15 Mar 2023 18:54:00 +0800 Message-Id: <20230315105400.23426-1-sherry.sun@nxp.com> X-Mailer: git-send-email 2.17.1 Content-Type: text/plain X-ClientProxiedBy: SG2PR02CA0030.apcprd02.prod.outlook.com (2603:1096:3:18::18) To AS8PR04MB8404.eurprd04.prod.outlook.com (2603:10a6:20b:3f8::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8404:EE_|AS1PR04MB9263:EE_ X-MS-Office365-Filtering-Correlation-Id: b9cf8f53-2066-435e-0238-08db2544055d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AbHb5YG7ndKGvNsfWomtMcOEmp3Bul+Mw359qoG+J2Fh6QM5qzDts9yBslEWu4nm4EFeHyktqdKxN8On7JVP7J7A1AfOiSyR4w+pXsjpBr98VH7cYT3m6ch2EeWQ9qxyvMKAIllpbcHP/3Ii9w+xLE3CXaQ429L9E9j9vmUSiEXaOC/pcz9idQtVQRV4qqXqEpDD2QshQyBj1IO1WSWKHFeQOx0GSZ44M6JVet4PUs5KF75e+nCfOTYq4dOsTlrWJb7r1Lyk7wHI8gnamN2TOD+YU5WPcf7Ug3ovyFDLMgrLOzVRHv8qxF0QGIJxYtm05Aw7DPYLU+a/A8z0Fq4PE3u7Zde4AXNC5x7TrtyqE5Y82YouQjSsEB/Goez4AY/EtqkWOuk6wrPJkHC+WuGAsc5knSbH+w/CZodNrJ5O+ILJW/sEMSDjMrPzomFvikcHYu8Wpl1gGqY7vHC0hVA3zkickIAebKJpz154dAf1v5JrgiKMh3F3KeG+6BhtMjFf6k7DpNULqSauuQdJcQVy1m9OnzkBfFf8DOEwoMmhDONLSheVp5OIHj0STqGoNZA298KrzGZmidEHP8WOhptYNjDUrxEX3L3Dn8FGOJ/qCIIMbWTvHDljCElM6+/IbNo5aifE5+PMZVDfry3HFIcs0Sa4JEwFXQzg5GnEUwyQDJtRKKQi2+bvjCxDJo+4IdlA3oSfeX9HhIIG2E2XD5EEkg== 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:(13230025)(4636009)(136003)(346002)(376002)(39860400002)(396003)(366004)(451199018)(2906002)(83380400001)(5660300002)(6486002)(6512007)(52116002)(36756003)(1076003)(26005)(6506007)(44832011)(6666004)(2616005)(316002)(186003)(86362001)(41300700001)(8936002)(66556008)(66946007)(38350700002)(38100700002)(478600001)(4326008)(8676002)(66476007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hUL88jz6qWz9urCKea+Envxim2EOdWsD9G6lzud9zL0BYTc42sicBjnKjxUvCm7PRweEEZWoWliId34+AIAKY8tVjNS0QVFzQXVSFOERdhBVO3NmyVS2jNt6ceGkDaX9+eWwXIbxGQPJe80eIljNfW/Yfjgo1OS9Lv6ZjpBiI1lzhU31UlZbfTisZT7aHEVSbSa8G+FCR9dMCrq12Ws3OhPu8KeuruhD22sH/64QkAkkRisyfHVriMdB2nf1zGatYFEWgrGGAkHU+v5JOXk8W6syzIXOLzN2Zszq475Rm0XK4YVRGpvfC6ZpNyq8mCBG6ENknvpXdeVy0CGwFirq86TH9EAdedNQDTKterZF8BBP8iMyi2qBCdQq9F9vmuYsCQJ2uLs74Ihc8M3MCv1h47rthrynPH3fxE0btwxtbP7RgHs3a9sufNLagT79cU0ouCqqasaq25y9U16Fpgcsq6012Xc5Xm62d9ysKmJkDvwlmm6VFEBXWRXPlT6q+sgWCMdMbYrUguFVyTRqvPnm2/ho2+n4Sgq5+udAkfd8rDMPDTfB9ADttfBwtWreETS5tICfIXZ9Vux/ujqy4dRy2xCYQ2OknH9+VPVwdD0vNYP3fQxXgxocWbLL4W9Ra6wDzCuz03jx8mQQ47y/GAKRVQ26a0PB1SmEeqI9D+aUU8lMrmBcWBgkUvKLdKdKo7/NzXfUENPnA2Mn+RXkCfINHRNmdmlLXr5DpZVUl6VVNIW2SycX9KtSJfucjf5IeAU18FRg5hAx6KWNL9M5ChAwtf7FXmNK6oz7NvUP2clsZX+X5FtmNGMrrMlHdy41l7zNDxeG0UPM/GcwSzdnjqxxJzXW18B1S6Lo+y/wrAOzuAlEPo6ZKhteKF5OCIWXPu8LseoaJ0CIGjivBnA3veltRTFEgnNmF3w/hlatV4jPVU+dvh0XG6Y1gUJQkN8J4btwZcX9mdZFlhhHKhXginVr3mpBilVVTDtoQlXIz/rGcu4nKCQCUzaXOivKUdJA/YuLwbRkKceHstS/GQ3+sL47wWEhRn9R7ozXyz+NYp+0wmhxkPfgEKPxBgcOOzrOHWraWQQ93RgPlANpTAD8gSOrPACi5SE3FBChzP2c5iqW8YQgJlG1CmSpaBaKzgNR2M917EFsa2IZZl1Kzm4PS9atT4N6D3e+VP0OwCXLnxU4Ew1g1MZWfxN5j7GVNXoUdMm+t0Itxj8+sUcOLstSk/fxErUbGXdqY2R64qe4BeuKAyrMzmOYn6eVgdNc+oobSU+6hMSDu/3BPz0lX9+9sVpxN3qFD8NYC3vQKJK68V/Fz6CeM8Svha6f5TiywpJzsk6E+vnxdwQYf5qevraq3eRe62VE9scrLt/JSRwdZWmnmUJ12eKZBBa3KT9nY2T9LcWnqy1GvhO1IFkGu571IYP9BbO1aGAqO4BOSaJgTkwH79R22mn0j1Btc3RwOmCqobPes1DKZukt5p37z/YSFsPmtzPexgv6hRhv3xR3v9c34BOrd1r4wg6rhZDhs/xTBHQQZb43LMVyQt6uzNmLSmXWss2OtrKyNygduP0u8iCj3H+7Xayk/eLz4odthQVSFxSf X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b9cf8f53-2066-435e-0238-08db2544055d X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8404.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2023 10:57:08.4323 (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: v1jWeLxnwscOEmeIrpiTxhLBC4Jm6fLzFW3Lyt5T3wzVknsCPGj5Rd15E64ZZKr1XCfDF4Pqpym6I+LTG047gg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR04MB9263 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760431651364687023?= X-GMAIL-MSGID: =?utf-8?q?1760431651364687023?= |
Series |
tty: serdev: serdev-ttyport: add devt for ctrl->dev
|
|
Commit Message
Sherry Sun
March 15, 2023, 10:54 a.m. UTC
For serdev framework, the serdev_controller device is the tty device,
which is also the child device of the uart_port device. If we don't set
devt property for ctrl->dev, device_find_child(uport->dev, ...) may
always return NULL in uart_suspend_port() function, which prevents us
from properly handling uart port suspend, so fix it here.
Fixes: bed35c6dfa6a ("serdev: add a tty port controller driver")
Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
---
drivers/tty/serdev/serdev-ttyport.c | 2 ++
1 file changed, 2 insertions(+)
Comments
On Wed, Mar 15, 2023 at 06:54:00PM +0800, Sherry Sun wrote: > For serdev framework, the serdev_controller device is the tty device, > which is also the child device of the uart_port device. If we don't set > devt property for ctrl->dev, device_find_child(uport->dev, ...) may > always return NULL in uart_suspend_port() function, which prevents us > from properly handling uart port suspend, so fix it here. > > Fixes: bed35c6dfa6a ("serdev: add a tty port controller driver") > Signed-off-by: Sherry Sun <sherry.sun@nxp.com> > --- > drivers/tty/serdev/serdev-ttyport.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/serdev-ttyport.c > index bba37ab90215..c58af8141380 100644 > --- a/drivers/tty/serdev/serdev-ttyport.c > +++ b/drivers/tty/serdev/serdev-ttyport.c > @@ -268,6 +268,7 @@ struct device *serdev_tty_port_register(struct tty_port *port, > { > struct serdev_controller *ctrl; > struct serport *serport; > + dev_t devt = MKDEV(drv->major, drv->minor_start) + idx; > int ret; > > if (!port || !drv || !parent) > @@ -282,6 +283,7 @@ struct device *serdev_tty_port_register(struct tty_port *port, > serport->tty_idx = idx; > serport->tty_drv = drv; > > + ctrl->dev.devt = devt; This feels wrong as you can't just create a magic dev_t out of no where and expect it to be handled properly. Where now is this dev_t exposed? Something else feels wrong here, sorry, I do not think this is correct. thanks, greg k-h
> -----Original Message----- > From: Greg KH <gregkh@linuxfoundation.org> > Sent: 2023年3月15日 19:10 > To: Sherry Sun <sherry.sun@nxp.com> > Cc: jirislaby@kernel.org; robh@kernel.org; linux-serial@vger.kernel.org; > linux-kernel@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com> > Subject: Re: [PATCH] tty: serdev: serdev-ttyport: add devt for ctrl->dev > > On Wed, Mar 15, 2023 at 06:54:00PM +0800, Sherry Sun wrote: > > For serdev framework, the serdev_controller device is the tty device, > > which is also the child device of the uart_port device. If we don't > > set devt property for ctrl->dev, device_find_child(uport->dev, ...) > > may always return NULL in uart_suspend_port() function, which prevents > > us from properly handling uart port suspend, so fix it here. > > > > Fixes: bed35c6dfa6a ("serdev: add a tty port controller driver") > > Signed-off-by: Sherry Sun <sherry.sun@nxp.com> > > --- > > drivers/tty/serdev/serdev-ttyport.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/drivers/tty/serdev/serdev-ttyport.c > > b/drivers/tty/serdev/serdev-ttyport.c > > index bba37ab90215..c58af8141380 100644 > > --- a/drivers/tty/serdev/serdev-ttyport.c > > +++ b/drivers/tty/serdev/serdev-ttyport.c > > @@ -268,6 +268,7 @@ struct device *serdev_tty_port_register(struct > > tty_port *port, { > > struct serdev_controller *ctrl; > > struct serport *serport; > > + dev_t devt = MKDEV(drv->major, drv->minor_start) + idx; > > int ret; > > > > if (!port || !drv || !parent) > > @@ -282,6 +283,7 @@ struct device *serdev_tty_port_register(struct > tty_port *port, > > serport->tty_idx = idx; > > serport->tty_drv = drv; > > > > + ctrl->dev.devt = devt; > > This feels wrong as you can't just create a magic dev_t out of no where and > expect it to be handled properly. Where now is this dev_t exposed? > Hi Greg, Now dev_t is the key point to get the tty->dev in uart_suspend_port()/uart_resume_port() and alloc_tty_struct(), it is set in tty_register_device_attr() but not in serdev_tty_port_register(). To be frank, I am also not sure if this is the right way to fix the issue, maybe we can have more discussion here regarding how to get the correct tty_dev in uart_suspend_port(). At least with the code logic in serdev framework we are using now, we will always get NULL tty_dev from device_find_child(). I believe this is not what we want here. static int serial_match_port(struct device *dev, void *data) { struct uart_match *match = data; struct tty_driver *tty_drv = match->driver->tty_driver; dev_t devt = MKDEV(tty_drv->major, tty_drv->minor_start) + match->port->line; return dev->devt == devt; /* Actually, only one tty per port */ } int uart_suspend_port(struct uart_driver *drv, struct uart_port *uport) { struct uart_state *state = drv->state + uport->line; struct tty_port *port = &state->port; struct device *tty_dev; struct uart_match match = {uport, drv}; mutex_lock(&port->mutex); tty_dev = device_find_child(uport->dev, &match, serial_match_port); if (uport->line == 2) if (tty_dev && device_may_wakeup(tty_dev)) { enable_irq_wake(uport->irq); put_device(tty_dev); mutex_unlock(&port->mutex); return 0; } put_device(tty_dev); ... Best Regards Sherry > Something else feels wrong here, sorry, I do not think this is correct. > > thanks, > > greg k-h
Hi Sherry, https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Sherry-Sun/tty-serdev-serdev-ttyport-add-devt-for-ctrl-dev/20230315-185913 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-testing patch link: https://lore.kernel.org/r/20230315105400.23426-1-sherry.sun%40nxp.com patch subject: [PATCH] tty: serdev: serdev-ttyport: add devt for ctrl->dev config: x86_64-randconfig-m001 (https://download.01.org/0day-ci/archive/20230316/202303160201.bnmM2caW-lkp@intel.com/config) compiler: gcc-11 (Debian 11.3.0-8) 11.3.0 If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> | Reported-by: Dan Carpenter <error27@gmail.com> | Link: https://lore.kernel.org/r/202303160201.bnmM2caW-lkp@intel.com/ smatch warnings: drivers/tty/serdev/serdev-ttyport.c:273 serdev_tty_port_register() warn: variable dereferenced before check 'drv' (see line 270) vim +/drv +273 drivers/tty/serdev/serdev-ttyport.c bed35c6dfa6a36 Rob Herring 2017-02-02 264 struct device *serdev_tty_port_register(struct tty_port *port, bed35c6dfa6a36 Rob Herring 2017-02-02 265 struct device *parent, bed35c6dfa6a36 Rob Herring 2017-02-02 266 struct tty_driver *drv, int idx) bed35c6dfa6a36 Rob Herring 2017-02-02 267 { bed35c6dfa6a36 Rob Herring 2017-02-02 268 struct serdev_controller *ctrl; bed35c6dfa6a36 Rob Herring 2017-02-02 269 struct serport *serport; 225acc66b125b9 Sherry Sun 2023-03-15 @270 dev_t devt = MKDEV(drv->major, drv->minor_start) + idx; ^^^^^ ^^^^^ Dereferences. bed35c6dfa6a36 Rob Herring 2017-02-02 271 int ret; bed35c6dfa6a36 Rob Herring 2017-02-02 272 bed35c6dfa6a36 Rob Herring 2017-02-02 @273 if (!port || !drv || !parent) ^^^^ Checked too late. Are these checks really required? bed35c6dfa6a36 Rob Herring 2017-02-02 274 return ERR_PTR(-ENODEV); bed35c6dfa6a36 Rob Herring 2017-02-02 275 bed35c6dfa6a36 Rob Herring 2017-02-02 276 ctrl = serdev_controller_alloc(parent, sizeof(struct serport)); bed35c6dfa6a36 Rob Herring 2017-02-02 277 if (!ctrl) bed35c6dfa6a36 Rob Herring 2017-02-02 278 return ERR_PTR(-ENOMEM); bed35c6dfa6a36 Rob Herring 2017-02-02 279 serport = serdev_controller_get_drvdata(ctrl); bed35c6dfa6a36 Rob Herring 2017-02-02 280 bed35c6dfa6a36 Rob Herring 2017-02-02 281 serport->port = port; bed35c6dfa6a36 Rob Herring 2017-02-02 282 serport->tty_idx = idx; bed35c6dfa6a36 Rob Herring 2017-02-02 283 serport->tty_drv = drv; bed35c6dfa6a36 Rob Herring 2017-02-02 284 225acc66b125b9 Sherry Sun 2023-03-15 285 ctrl->dev.devt = devt; bed35c6dfa6a36 Rob Herring 2017-02-02 286 ctrl->ops = &ctrl_ops; bed35c6dfa6a36 Rob Herring 2017-02-02 287 aee5da7838787f Johan Hovold 2017-04-11 288 port->client_ops = &client_ops; aee5da7838787f Johan Hovold 2017-04-11 289 port->client_data = ctrl; aee5da7838787f Johan Hovold 2017-04-11 290 bed35c6dfa6a36 Rob Herring 2017-02-02 291 ret = serdev_controller_add(ctrl); bed35c6dfa6a36 Rob Herring 2017-02-02 292 if (ret) aee5da7838787f Johan Hovold 2017-04-11 293 goto err_reset_data; bed35c6dfa6a36 Rob Herring 2017-02-02 294 bed35c6dfa6a36 Rob Herring 2017-02-02 295 dev_info(&ctrl->dev, "tty port %s%d registered\n", drv->name, idx); bed35c6dfa6a36 Rob Herring 2017-02-02 296 return &ctrl->dev; bed35c6dfa6a36 Rob Herring 2017-02-02 297 aee5da7838787f Johan Hovold 2017-04-11 298 err_reset_data: aee5da7838787f Johan Hovold 2017-04-11 299 port->client_data = NULL; 0c5aae59270fb1 Johan Hovold 2020-02-10 300 port->client_ops = &tty_port_default_client_ops; bed35c6dfa6a36 Rob Herring 2017-02-02 301 serdev_controller_put(ctrl); aee5da7838787f Johan Hovold 2017-04-11 302 bed35c6dfa6a36 Rob Herring 2017-02-02 303 return ERR_PTR(ret); bed35c6dfa6a36 Rob Herring 2017-02-02 304 }
diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/serdev-ttyport.c index bba37ab90215..c58af8141380 100644 --- a/drivers/tty/serdev/serdev-ttyport.c +++ b/drivers/tty/serdev/serdev-ttyport.c @@ -268,6 +268,7 @@ struct device *serdev_tty_port_register(struct tty_port *port, { struct serdev_controller *ctrl; struct serport *serport; + dev_t devt = MKDEV(drv->major, drv->minor_start) + idx; int ret; if (!port || !drv || !parent) @@ -282,6 +283,7 @@ struct device *serdev_tty_port_register(struct tty_port *port, serport->tty_idx = idx; serport->tty_drv = drv; + ctrl->dev.devt = devt; ctrl->ops = &ctrl_ops; port->client_ops = &client_ops;