From patchwork Sun Jun 28 01:14:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Qiang" X-Patchwork-Id: 214793 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=CHARSET_FARAWAY_HEADER, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9642FC433DF for ; Sun, 28 Jun 2020 01:14:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5BE7920760 for ; Sun, 28 Jun 2020 01:14:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=windriversystems.onmicrosoft.com header.i=@windriversystems.onmicrosoft.com header.b="nY6DGvTP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726666AbgF1BOr (ORCPT ); Sat, 27 Jun 2020 21:14:47 -0400 Received: from mail-eopbgr750051.outbound.protection.outlook.com ([40.107.75.51]:51567 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726378AbgF1BOr (ORCPT ); Sat, 27 Jun 2020 21:14:47 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TQvckncxK/yfQTQvBPPYHfNUTZoOZnS/gdxdXhAH0me3SlmOv66hteGclnBxgi78bqLgu+oXYJmExenWIXw73DkWzKmx1xG+rjWsjhQq+y42v5M+vciCw1LCDmIhtve1Ch+f/zFakKugEQaUPN4PiBPJsk1l9GOplrzFqo5Cf4xY5wiEt/LwPQl/H4koi6lMxeRIJGj6QQl4xhpCJoqIi559fsP00y4Yh0PPjfzU02VAcK+4h3cpTkZQ3/Oo7Orbwg8InjA3x6F6/R1jH8o5pBYRCHlgSHbpqTAy1qkXa0CtR7rcHiFnlLO2C/J3HDAxYP2b5dVJJAb7hC0jEdAqtg== 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-SenderADCheck; bh=OOU1rFwb6+wypV9rPQSji24NFpeO7zZlatj4qajH1vI=; b=Zjd1eoHJNNdoogFt7hZRn53vTSbVqKahabkEponYhLwJQAhwT3+Wll3OL+QL4E2K8LBKIK+pxFVt9Bm9BMJCT+UMxcjY1Z3YWHIopL+4JSlevs31s/oN0d6Mrt5pH9XYQyGwX+GN88LTds/vKsYED+YT9tTewGpko3NkpykB4qZYfmbu28qmsIggb2DpNJD4Ce1PzotoMB+beAvSk6h8Yq4izL5rXgg7p/hIxR6WnFxKmCvhP1AOqg0+oixTWzvWkFFhtEsyBECdp15YEZUKemy+lOcr+cFdmhfwFUo4YLRt6VN3hKzeCFlRhb1Byt+/MCP3KNXhlcJo0JM9h0ACTQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriversystems.onmicrosoft.com; s=selector2-windriversystems-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OOU1rFwb6+wypV9rPQSji24NFpeO7zZlatj4qajH1vI=; b=nY6DGvTPax4+66AjybZ7moVmWfNwEB6SqV/FVNW01+0+8s5Z6ZTSpqoZ/V4ptjWPnkhqpKnKwIwcNHQ5CMh0vPlhWvCo+FHSwobIkmuhkLk24iWvi1IpfDFuA3etCvM2BBpyOKgak3mMONhGKnbE9MvzuQIbSeR4WbJERz+HIvU= Received: from BYAPR11MB2632.namprd11.prod.outlook.com (2603:10b6:a02:c4::17) by BY5PR11MB4008.namprd11.prod.outlook.com (2603:10b6:a03:186::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.25; Sun, 28 Jun 2020 01:14:43 +0000 Received: from BYAPR11MB2632.namprd11.prod.outlook.com ([fe80::3d7d:dfc1:b35d:63d1]) by BYAPR11MB2632.namprd11.prod.outlook.com ([fe80::3d7d:dfc1:b35d:63d1%7]) with mapi id 15.20.3131.026; Sun, 28 Jun 2020 01:14:42 +0000 From: "Zhang, Qiang" To: "balbi@kernel.org" , "felipe.balbi@linux.intel.com" CC: "gregkh@linuxfoundation.org" , "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: =?gb2312?b?u9i4tDogW1BBVENIXSB1c2I6IGdhZGdldDogZnVuY3Rpb246IHBy?= =?gb2312?b?aW50ZXI6IEFkZCBnYWRnZXQgZGV2IGludGVyZmFjZSBzdGF0dXMg?= =?gb2312?b?anVkZ21lbnQ=?= Thread-Topic: [PATCH] usb: gadget: function: printer: Add gadget dev interface status judgment Thread-Index: AQHWQviu7UnxlHpgaE2VuvYHPsK4SajtTPLn Date: Sun, 28 Jun 2020 01:14:42 +0000 Message-ID: References: <20200615094608.26179-1-qiang.zhang@windriver.com> In-Reply-To: <20200615094608.26179-1-qiang.zhang@windriver.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: kernel.org; dkim=none (message not signed) header.d=none; kernel.org; dmarc=none action=none header.from=windriver.com; x-originating-ip: [60.247.85.82] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 6b7a9660-0855-4f5e-78b6-08d81b00a36a x-ms-traffictypediagnostic: BY5PR11MB4008: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1850; x-forefront-prvs: 0448A97BF2 x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Bt3tzURCQhOp6cHjufQry3PmVzoo5H+7R7DHhXF0bs/6tCpakcQ0Osd/LI+Sw5vFFiqa8XWdy9qk6jwOveu0VI6ugMzeoB5+8Aq6MeGtIyzOccd2uv+fI52OqYiFBdkmFyh5rTJaUhgw/48witdZikvcUeFF6IN9XmkT99w+uvEZoJ43N/7gbth6CwQL9/HddZBpdgBev/3WhoD+b/1kFJXN00MJuKUNrAhnRSW94XCveaG81cJyZsfnpLo0d40CYcTF5AjwL94pEVodWlO99JKF0ixu0AzuNxEkRV9mwt5A2qWsPO0e9UDRyf334zpmbsNIbzZOMC3CENC220sWTg== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR11MB2632.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(366004)(376002)(396003)(346002)(39830400003)(136003)(2906002)(52536014)(8936002)(316002)(5660300002)(33656002)(83380400001)(4326008)(91956017)(71200400001)(66476007)(66556008)(186003)(64756008)(110136005)(86362001)(224303003)(55016002)(9686003)(66946007)(66446008)(26005)(76116006)(7696005)(478600001)(54906003)(6506007); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: 5lTRiVt0ZzVppjikJ2TfMyVo74bAerArlnrhlcAHDtDzaFXbsq9hIpAlOSAryScQHEWLGQtgKn+yOGUktYwPYAo/lISO/S7GtanXDg+HDu2SDlyFwZycKZ2CYSNPSKJrvZ4V/by1SRt7sjuk2aJjK7tOD34epYd0QXgDwr8vGH+qwbmf6+ockiuuk5MMwG/RdbwPJItvggOO+OrA78bXkGw3WvEWWveMoXhYtduQHQx/gXpVBRf25syTJdNEz53sxomh6+2eioBZqL0y5LRwio9HAOZzx0oL7UoSjTnVrCi/rjcpF+EYmspz0cbXgQ7taSZnRnzRsI5OCTurX6qfe7rsxriXQIJq1c3I2Xrcn7zz3IVIxB8vm8tN3L+TXpQQPKCahfgzwvE9b6tIYXJq8TD+L7RgdZFePdayddRcVCtJWn/S+6TcqSWQ2TfHH067VVbQeD9daauKLt75rvZ1BhxSDgxFCp+S1pDgFLf48EY= x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BYAPR11MB2632.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b7a9660-0855-4f5e-78b6-08d81b00a36a X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Jun 2020 01:14:42.5580 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 5UmPkKSJg5HVcAsZbO/j9bMirtIivgxY0tpx+62LhyWRWb/exiEtB/E8h9g0LuhP44zHraj3O4hLa4mcqldXR/lSRKUFnxuNq1S4/FuHz/A= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR11MB4008 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c index 9c7ed2539ff7..2b45a61e4213 100644 --- a/drivers/usb/gadget/function/f_printer.c +++ b/drivers/usb/gadget/function/f_printer.c @@ -338,6 +338,11 @@ printer_open(struct inode *inode, struct file *fd) spin_lock_irqsave(&dev->lock, flags); + if (dev->interface < 0) { + spin_unlock_irqrestore(&dev->lock, flags); + return -ENODEV; + } + if (!dev->printer_cdev_open) { dev->printer_cdev_open = 1; fd->private_data = dev; @@ -430,6 +435,12 @@ printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr) mutex_lock(&dev->lock_printer_io); spin_lock_irqsave(&dev->lock, flags); + if (dev->interface < 0) { + spin_unlock_irqrestore(&dev->lock, flags); + mutex_unlock(&dev->lock_printer_io); + return -ENODEV; + } + /* We will use this flag later to check if a printer reset happened * after we turn interrupts back on. */ @@ -561,6 +572,12 @@ printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr) mutex_lock(&dev->lock_printer_io); spin_lock_irqsave(&dev->lock, flags); + if (dev->interface < 0) { + spin_unlock_irqrestore(&dev->lock, flags); + mutex_unlock(&dev->lock_printer_io); + return -ENODEV; + } + /* Check if a printer reset happens while we have interrupts on */ dev->reset_printer = 0; @@ -667,6 +684,13 @@ printer_fsync(struct file *fd, loff_t start, loff_t end, int datasync) inode_lock(inode); spin_lock_irqsave(&dev->lock, flags); + + if (dev->interface < 0) { + spin_unlock_irqrestore(&dev->lock, flags); + inode_unlock(inode); + return -ENODEV; + } + tx_list_empty = (likely(list_empty(&dev->tx_reqs))); spin_unlock_irqrestore(&dev->lock, flags); @@ -689,6 +713,13 @@ printer_poll(struct file *fd, poll_table *wait) mutex_lock(&dev->lock_printer_io); spin_lock_irqsave(&dev->lock, flags); + + if (dev->interface < 0) { + spin_unlock_irqrestore(&dev->lock, flags); + mutex_unlock(&dev->lock_printer_io); + return EPOLLERR | EPOLLHUP; + } + setup_rx_reqs(dev); spin_unlock_irqrestore(&dev->lock, flags); mutex_unlock(&dev->lock_printer_io); @@ -722,6 +753,11 @@ printer_ioctl(struct file *fd, unsigned int code, unsigned long arg) spin_lock_irqsave(&dev->lock, flags); + if (dev->interface < 0) { + spin_unlock_irqrestore(&dev->lock, flags); + return -ENODEV; + } + switch (code) { case GADGET_GET_PRINTER_STATUS: status = (int)dev->printer_status;