From patchwork Tue Jun 30 01:19:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Qiang" X-Patchwork-Id: 11632969 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 27A786C1 for ; Tue, 30 Jun 2020 01:19:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 03E9720780 for ; Tue, 30 Jun 2020 01:19:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=windriversystems.onmicrosoft.com header.i=@windriversystems.onmicrosoft.com header.b="pTxMyJPd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728329AbgF3BTf (ORCPT ); Mon, 29 Jun 2020 21:19:35 -0400 Received: from mail-bn8nam11on2051.outbound.protection.outlook.com ([40.107.236.51]:26438 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726436AbgF3BTe (ORCPT ); Mon, 29 Jun 2020 21:19:34 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dfdq/wKBl/ZZuIOO2odQ0BOycGr1QVOXP8LuhV8dwo7x/JmYzqirR9hfEd2JamDceT1zrVtcHLu2IoFw/x4ct/1HiywrVfJBJer2OP9HlDhCfB7fBUs5Gy29gCrOeNE5QUzNwQ8i/eY50NksTaLU+cWAd61oeyOuI2AHsttItx/zvyV57gJ7/mOYjU5LrSWktxFi1XALYS9IPjBi6blkwsxrxGNyBQaL1Yfjb3j5obwMMmq1nM5/pr4zjlGpXYt3KCJ+00tDKfUTM++HvHD2ZvvqsBLRQXBx4d5XnLfCLxmV46w9bSpvF5AOOfGgGPnKNompXB1CaMgMw5BTrGynWQ== 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=WyZHVaOHgdyT9xunGQ0c3lauNf0VHuCVzT6JwK1gXHc=; b=Y+qzC6NbO0Yi1uFtt4bGoB8IpOnkiRyF5DlivZJxtuHpeELabtcvSOIt6q4iOGXQTcAUankrfKDa3Vo8B6+/DXL7eibZueMg5IRJB4Vku1GuC00HxWE8KJfY0bxZooif+K5JcGWtso7Xq/Q3KUAjf+WhsRsYRI4SUp2gLyA6ZaJkmx8sE3z914mYkP76RjFjYwq8x/kQHqr+zj+1sPqXrxKN0nEpi0CNqI/D+barfxCPxUgdYxbmLll+8gx4uebFYuRsPQAYkJV/5dbHCon5JfyR/HTaJWk6fmr9MTE8NN8I1gg7iT5vAOL9TNt6AV1iJLpakc4vppK41nV9qPaoWw== 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=WyZHVaOHgdyT9xunGQ0c3lauNf0VHuCVzT6JwK1gXHc=; b=pTxMyJPdocSRNEIAiN+t48EAxWlHy9LwbLM6XSihJocUQwXs1MqWobtPbsI2xN9FPs4rFknS/bH6ZhC2gwDAfc+0ku+UCLX4nGk4BdVBvoj8DoFLwWTrMJCcZN8pRQKw2VqrxYuEmtuZVZfL+3ubcX15Ry8302gVxqvIkm6xsn0= Received: from BYAPR11MB2632.namprd11.prod.outlook.com (2603:10b6:a02:c4::17) by BYAPR11MB3446.namprd11.prod.outlook.com (2603:10b6:a03:1a::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.26; Tue, 30 Jun 2020 01:19:30 +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.027; Tue, 30 Jun 2020 01:19:30 +0000 From: "Zhang, Qiang" To: "balbi@kernel.org" CC: "gregkh@linuxfoundation.org" , "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: =?eucgb2312_cn?b?u9i4tDogW1BBVENIXSB1c2I6IGdhZGdldDogZnVuY3Rpb246IHByaW50?= =?eucgb2312_cn?b?ZXI6IFRoZSBkZXZpY2UgaW50ZXJmYWNlIGlzIHJlc2V0IGFuZCBzaG91bGQgcmV0?= =?eucgb2312_cn?b?dXJuIGVycm9yIGNvZGU=?= Thread-Topic: [PATCH] usb: gadget: function: printer: The device interface is reset and should return error code Thread-Index: AQHWTO4m/7Kq2lPOa0yJ5PnFdxMxZ6jwXoAy Date: Tue, 30 Jun 2020 01:19:30 +0000 Message-ID: References: <20200628015731.16566-1-qiang.zhang@windriver.com> In-Reply-To: <20200628015731.16566-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: 7caaadca-7ed0-481a-6969-08d81c93a3b8 x-ms-traffictypediagnostic: BYAPR11MB3446: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3173; x-forefront-prvs: 0450A714CB x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Q8l8IVAyrD/8cXyFJbCwdgMX/reEjML2ku+IhUEN20cGWnKXEMPAxQVqLVG6PBrB+H1T3kdwxaTchyiO0dImAw5Fi1XgQfXHAHsjHdnznrmU9YmlZOhkJXA32TgGZsjVNAhhKlKO+1yOPLt/drEFgmWpAE6E+kVkjtzQdqLscCu/+7H6yvD6gX1O2UViHBB1jif5fBLXD4R+dgVvv3tAuP8FGrlFlkTQye1H8+xe/+ZOyQImWfB7ZbZasLLbX+cEeSez8e5Q2gwuTtmiGKNZ5e777IhhpjdoP0obw1Hz6e6mrQWwUT1KFF8zlArKlPPvKPVtPq7mKTEdh6xCfsAawg== 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)(9686003)(55016002)(86362001)(52536014)(66446008)(64756008)(66946007)(76116006)(91956017)(66556008)(66476007)(71200400001)(5660300002)(6916009)(224303003)(83380400001)(6506007)(8936002)(7696005)(186003)(4326008)(478600001)(26005)(316002)(2906002)(33656002)(54906003);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata: D7tDNaKAPGBUkNPP6C7zkliDzK7gfvupN5d5zl+51iOYlg4kKR4WNFep69A5faObPzmh+o4EI1g0rBwv5y1EYlSLJvXHRYvYsJBHKLdjOEPQDYtQQrjJo8RevQqhyiiqvD5+A+LEC4kjONwz9FF2oDHSVbp6jRiXNN1LMDlg9jSOru9kvzyVtGhx8eo5I1RQBsZ+WJgiL6VoT/cJqLXn9zD6jhdTK65vmBUnrjfsP4t3LR613ppsN050msxcCgnuwS6o3wPwMwoNo+j9AcjPPPYRJNt8pIq1F+86nf1GKMEEnywiC7YlY5e7cqiIUAU9PXswnwGQnjWE+I62Um1EkGdhEetQ4Yu4yTqIaDzAG7fjj2xQGE6uiVFyCL7XPwgappmCC5CVsnGKM2vJtpYxdGgaL4ZMpxeCfA9OHTc5Cy2+YiQpc9kWdQ5WncS8x8f1WkdKmp2oKob5mUteHPqRALj3Mz+F320HKevTVlDT/Zo= 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: 7caaadca-7ed0-481a-6969-08d81c93a3b8 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Jun 2020 01:19:30.3748 (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: bdFI9eh7CO2U8aMXFZNA1zP6ULF07B2/GMju69PTYU4pQoBMNb5bE7EffiABZ2fvL4knzvMHtYvtIOBfQQ7fDpUnN5mD/E2XCi5irC6emxc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB3446 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Hi Felipe, Please check this patch and make suggestions . 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;