From patchwork Wed Jun 24 08:59:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Qiang" X-Patchwork-Id: 11622705 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 74E3992A for ; Wed, 24 Jun 2020 08:59:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 57D2D20B1F for ; Wed, 24 Jun 2020 08:59:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=windriversystems.onmicrosoft.com header.i=@windriversystems.onmicrosoft.com header.b="OMGl3eE3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388531AbgFXI7o (ORCPT ); Wed, 24 Jun 2020 04:59:44 -0400 Received: from mail-dm6nam12on2087.outbound.protection.outlook.com ([40.107.243.87]:37344 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387491AbgFXI7n (ORCPT ); Wed, 24 Jun 2020 04:59:43 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Chj6KYRgxiOdvkgLgmTlm+YhwkNmLJobrS9VOPh+m3qxZMnkKLfIM4/a8nMDf3ATFdSIoIFp5rq56lnEmkLHK9U8vKPQIzZ2kgCjGW55kZZbi7aAhFTutUpJf3+CMRSsSMiaNLF5/J9MEmmlo3zBQAVcL00WbQ9YhBDXVoXSAjhKm0vyI50MhPjbATWoQZRoyouO5KZI/WXXEg6oNotj4OkgGlNlr6dt1XMI//QeWfnXKGooRUaR8JrsOVDu9ixfpi3IQfWsugUQ7vXaoSXlEjxCAKmcAOmSS9UTDvcAMTTjamVY+v9zJYmpoN4L5MKk+c8RIeSKH8GlS6l+wd9kQQ== 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=CRxp9wK9Nl9F91Rjm5N/DQPlxWsK+Hf52pGQuA0q8bk=; b=PnhZYTSRCX28DqXdbrsIhBspScTz1UpklKQUMG7/snvuv7djXvkQ6LvEdVHvAaCOvLSbNINvfbPppGjc2P08DPy694Km3mOyi5PaBigz5KfW6OVeRWXmBboDV9JOn6w7EP/PKS/0J6e/nCjiOLPHjUKj1s/yGPtuagJ29ZxRVbYEUE70y/Ubokdq80+nFMOOQzDBI+Ff/9cL6US9hFmOS9+jKbc8EpdzEew5MpI4uOx1yThqFeZWzQPXkSLJHWp1fVFCzEsv9bG31xsrKw7qo/TA30YdfftLLPLuWPKfO6OOuqAOv0fke4xoJhAzosy4YbMJYLhDhnB8o+61uWE1sA== 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=CRxp9wK9Nl9F91Rjm5N/DQPlxWsK+Hf52pGQuA0q8bk=; b=OMGl3eE3GQ5Qu+n2+Lijfye1DJK9YkofiqJJYljRIYUCF+ME8LJPiR17ugfSDO9mcPs90tJdknUISPj6I6CDLjwmNTPcDAJN7c8JZlg8GzSAWrKbi+RvuihXqSXC3cBCkvzrtCD8vL9jtfMkrHpeYqXhJJYRx3m+00aNdftaw6Y= Received: from BYAPR11MB2632.namprd11.prod.outlook.com (2603:10b6:a02:c4::17) by BYAPR11MB3813.namprd11.prod.outlook.com (2603:10b6:a03:ff::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.24; Wed, 24 Jun 2020 08:59:41 +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.3109.027; Wed, 24 Jun 2020 08:59:41 +0000 From: "Zhang, Qiang" To: Greg KH CC: "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Felipe Balbi Subject: =?eucgb2312_cn?b?u9i4tDogW1BBVENIXSB1c2I6IGdhZGdldDogZnVuY3Rpb246IHByaW50?= =?eucgb2312_cn?b?ZXI6IEFkZCBnYWRnZXQgZGV2IGludGVyZmFjZSBzdGF0dXMganVkZ21lbnQ=?= Thread-Topic: [PATCH] usb: gadget: function: printer: Add gadget dev interface status judgment Thread-Index: AQHWQviu7UnxlHpgaE2VuvYHPsK4SajnhMek Date: Wed, 24 Jun 2020 08:59:40 +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: linuxfoundation.org; dkim=none (message not signed) header.d=none;linuxfoundation.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: 87a454d1-31c3-482c-de87-08d8181cee68 x-ms-traffictypediagnostic: BYAPR11MB3813: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2512; x-forefront-prvs: 0444EB1997 x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Dbcbuyo93hR2uOvtG1rHDFH0uukh9rJceif7AQ+BmtutlXw/ooyyNT7A2mPXZLmhA/9ppM5RvqWr4VjKXmsFjJL0cgzBwh8Q/HiZRsdI3lUVg6zVWOGntaP2z4NF5aCTnJJa88GLbmje1tp0/0AivBf8KZYxTwprGGBua9OXhtF4g5IwDsaTcNBjtI1VTo7j6faMCoWODCy/PgroZ/b3lXSAkiqU2AJDc+DSz4HMHh2ypx4Yt2k1XBcYb8zTYsOcJrDVcWwYsKVdxgP8ggba+E0WvTWZ0qcgXVSK+roFJYvzIHs/VfQe40m9gnI552R9DSBf4ngYNPIiL3e1+AYGpw== 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)(39830400003)(136003)(396003)(346002)(186003)(4326008)(2906002)(54906003)(9686003)(71200400001)(83380400001)(8936002)(478600001)(7696005)(55016002)(6916009)(86362001)(6506007)(316002)(66946007)(26005)(33656002)(76116006)(224303003)(66476007)(66446008)(66556008)(64756008)(5660300002)(52536014)(91956017);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata: Gl+FzeoYgSryHEBSG0d5Iu6CuTspxcucLO9PkxVVkql/tXI9Y5LlO8Sb2RMpsn1swF14CMib5hzzagSwZDl7CpHgdmpU42xlOoAPV0vsAcgiKXa1CkTcBfQVcm0V+vJBF15i6QZjQfRaMytNhCm/cpBdEkIQGW+3kNamT5RxwfUuTURznDlxRMHkVlNcLmW/S8Rn2LMqmiffYCFfXnHOCDt/d5ktserv8zU19lmdZzwYSENXCoSfIcOOoJhgmxezOFxnLJEdZKN9oOBv7lNVPR48+Wjc90f/bvZuVUBChnIKVTuszEzJrm9q50A75g2u801blAeJXlFBnY9fQsm5iXXVCvVACRtb0eUtMimTeGI0koe37PE8jhuuLLHEPuQ6ratDWDuizZbbi8N8t3OQj+xvLFETkXC4CehTX5HzVyhAehkOn6/zGu1fhGWG6r1k0grSdlrlIWRfU8t5FAqJD5iBPxrjJNPMZAJQMfTGvN0= x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 87a454d1-31c3-482c-de87-08d8181cee68 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jun 2020 08:59:40.9367 (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: E2gJnjyQJTxTLICx3zkD4FElotS4k4z2HHetm0lTvSNaI8bQk1OfClJIZ/ybNWoX43OyllF8gLBKanRRT7yyNp6rcBzihf6OCWHMQnOzF6Q= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB3813 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Hello, Greg KH Please have you review the patch? thanks Zqiang 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;