From patchwork Wed Jul 8 02:22:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Qiang" X-Patchwork-Id: 11650559 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 75C2814B7 for ; Wed, 8 Jul 2020 02:23:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4EB0720786 for ; Wed, 8 Jul 2020 02:23:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=windriversystems.onmicrosoft.com header.i=@windriversystems.onmicrosoft.com header.b="o8itE1LF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729399AbgGHCXC (ORCPT ); Tue, 7 Jul 2020 22:23:02 -0400 Received: from mail-eopbgr700073.outbound.protection.outlook.com ([40.107.70.73]:55617 "EHLO NAM04-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729199AbgGHCXC (ORCPT ); Tue, 7 Jul 2020 22:23:02 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WeN74N3ZQGvfMJBLIVqIYwuuTyTVWi/yP2H30x+/IAV8Wa2VcYfqX/jfGRrnpppBem77/ouUVgilARHAPf0fnKeJKfnGuCIvPcNMpdr3e6PCjwtm8iyTcanbuVk8+3VuBxc15wPlL/sCpS3260bDR0nk6kSM/Ca0D1ToJWNzRlP/QWnO8XZvzT4uu+JewUJquiLgKbhL4Lkp1/oepz08WfHQ83xqvWYK0+tJACm0IUMtBxABbVknySXAR4SDlFz+KepXNLZpIlzzJMYSv6q3YNnqwK3jf9LpzRb8Rp68rphzDNfCvYjMR9MVQIh3Pm7jKVRIu30PswbuhMHRodhkPA== 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=fNxVxdWM+czGqT3BfTEr2MFR456KNseZH2Q+TcWhWvA=; b=kLSsTMEr9QdTxODJIgzIkvnC+k9uxrdO6H1iVK868Am5Wpb9LImxg6t8iZr6RuKUNj10LJWVWvRypy4KPI88YXFOV6TT/NRP3QlM4EzGbABXCaMgWKe2k2XyrGhf4hKlTP4Myhe6apiLB+zxMyAhI9g5gbUJnx1wuaJYyFvlN2oXV2lO3H6TEtK5DG4dDx8zCK+0VR+cF6S7Hi3KTEuRt8wN2TCeFQRh1TCQAsmWNUsgoEYFEOJpflwcK7j6p4M4VG1hroYuCiLsff6+qQT7IA8mxVAdg41fspfZLwUsWkCfH9wc8nFNm89/jhDHBSuIPXIXIir9nt5fL6D/NuQd9Q== 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=fNxVxdWM+czGqT3BfTEr2MFR456KNseZH2Q+TcWhWvA=; b=o8itE1LFJFNIhNbzebuubpzn1jIoGWfO35dr/3Wbeh3NivBEsE1JCoaEoLBB8jyEnsoriZXOk8nwOGus/Sm7oPyGKiJc5An6BtfzTONMyJ21yL3NKGRMVfFNial9M8gJk1OXghnbPOlojkLIEPZEzs17XPLAMpGy7rd9zqN3vT4= Received: from BYAPR11MB2632.namprd11.prod.outlook.com (2603:10b6:a02:c4::17) by BY5PR11MB4387.namprd11.prod.outlook.com (2603:10b6:a03:1cb::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21; Wed, 8 Jul 2020 02:22:58 +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.3174.021; Wed, 8 Jul 2020 02:22:58 +0000 From: "Zhang, Qiang" To: Felipe Balbi CC: "gregkh@linuxfoundation.org" , "linux-usb@vger.kernel.org" , "balbi@kernel.org" , "andrzej.p@samsung.com" , Felipe Balbi , "andrzejtp2010@gmail.com" Subject: =?eucgb2312_cn?b?u9i4tDogW1BBVENIXSB1c2I6IGdhZGdldDogZnVuY3Rpb246IHByaW50?= =?eucgb2312_cn?b?ZXI6IEludGVyZmFjZSBpcyBkaXNhYmxlZCBhbmQgcmV0dXJucyBlcnJvcg==?= Thread-Topic: [PATCH] usb: gadget: function: printer: Interface is disabled and returns error Thread-Index: AQHWT3bFuthXI8KBRkiJKgy7AeHyCKj6CuUdgALyOKU= Date: Wed, 8 Jul 2020 02:22:58 +0000 Message-ID: References: <20200630052331.33020-1-qiang.zhang@windriver.com>, In-Reply-To: Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: linux.intel.com; dkim=none (message not signed) header.d=none;linux.intel.com; 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: 213a9969-c57d-4369-34b9-08d822e5d4d5 x-ms-traffictypediagnostic: BY5PR11MB4387: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2043; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: UFAzhGqM37p9/ujDRqwvwL8KovPlev0GTvOwFB7muuEUW9nI3h3aCUGqtBlwxFpcriMH6mrJyJ1qLkBjvoe3TR1JNj9m6IFnJNfkyP+SZix8wJF/loeTiJ2gEtQeGb319tzY914wOGw95dsC4FUeImGd9WMaadCQkfRfPstGrgSWNLuryMIfU0Dp58LiSakuUcTLiK491WlOxlebyAlTeIyuIvZLabaR2Eavjf+jWu0iIzzr8D8W5HJHkSuK4h1Ah9BtFd9+gZ/W64s7Ydw2IntmjkLIvQDSZiCNfTv0ocJs5dVH6YC3CtvdvEbJ//ZlHIuY9m1B15u1VuC0VtLNDw== 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:(39850400004)(346002)(376002)(136003)(396003)(366004)(54906003)(6916009)(186003)(7696005)(86362001)(55016002)(71200400001)(9686003)(83380400001)(5660300002)(33656002)(4326008)(2906002)(66946007)(91956017)(66446008)(64756008)(66556008)(66476007)(76116006)(6506007)(478600001)(26005)(52536014)(224303003)(8936002)(316002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata: DdaGzAIxt5DZMVQ4acpWu0eoFiXhxkskaTxi0+EMRmeZI7aVseENEJ4TVeNRcjt/kZeBWSwBJu5VW1Nlq2QeHo1Y28oqjC49lLmWWMfuOrnC4Z0CfWlfldeCqoYkNDd4SI9hbDGI/21aTDpY1k37FNq0CLBzdw2z85c6mLSrUxIMuXnJ0AnEnZvQR4/V5UAkVMK3ssH1bQ68NjvSjNaeqA7ER4ipxEYYjO7wxDDGbT4HPr9n+Er4YymcVcgC4zbMIDiEes4g7e/hPIYywPdQ2E1R8VVsnvD0SmC2N4edM9UrjX03xJwUhZlDKWSiDTapQLGV/3vBY1N5vgkwl0P8NsVab8THAONbCR5hzWeTpwHgoQn41G5yAtuuHLLGUDSxvb0b1o6IASH8fShoark2/DNbWSDsNUqO/8NUPnIRSFGC+FHO8C/wHFBjnro6FZhdrIWE81Zey4VqUAxKYhAq8W4qhDhLZG7DxuKaJfDV2yg= 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: 213a9969-c57d-4369-34b9-08d822e5d4d5 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Jul 2020 02:22:58.5463 (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: ZEK5Oiug24GeA4917yL/Eirn8AcSX6aI/rCImpcvthiGCD1bmYgzC67eWxrO1mOXoSJhU4hBG0M55Dwkw6pCje/CqkCqTzEapE7/mEjq5JI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR11MB4387 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Hi Felipe Please review this change. thanks Zhang Qiang 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;