From patchwork Tue Nov 5 10:36:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11227489 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 16C421986 for ; Tue, 5 Nov 2019 10:36:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E91E021929 for ; Tue, 5 Nov 2019 10:36:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572950208; bh=tq2fV4Uk7pdWjkTra96E0NpwhoUCkh2xwiqRIU53RD4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=GITlflXTioPZZO4XqpHREjuqcu3dz2uipvJf1AwmHPbrYJuHILDadGd/WznByxdtf hgP7PlWDP4GNroVXnZBogIMwXwtyvhCdwThXW36xb1ZVWbUc2pbibDF5eKnvykO/Hr 2LcMz0yyeAtb1JTLFpoJAuhklNvCMwe+Hl6X5Znk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388752AbfKEKgr (ORCPT ); Tue, 5 Nov 2019 05:36:47 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:41732 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388643AbfKEKgq (ORCPT ); Tue, 5 Nov 2019 05:36:46 -0500 Received: by mail-lj1-f193.google.com with SMTP id m9so21167629ljh.8 for ; Tue, 05 Nov 2019 02:36:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ioe9GPDGvuZyKn6ebVigNEF06QTE8TyNHyGBEUos8jo=; b=McCyO1wP2e/IGgnfWvRv563CQvrUOHdzDJPUljhuaxRBrr2ulpkyq/OguyXBfY0CGm NoOOFpV9KbfWSRkiQPHVk0XN8lkzKhEwvufM7EvKZmUsiXrs2TqLV2lXY/OwMO+q7Tz9 7/h40oZilprcxf4plE6gA5ny6NDq0CJK91DAyL1WFeYMsaMnGEOAN9UMp6Y0OmTbDYag INSdRi2itWcxIBBSusZtSaGoO0OGTMpw4oBhKblLpm+xQrs/f7fugvY+VqpfGHBDhPhm A+rsZnfRiOyhTGnYADh4p0E6mZ/AHuywZa+HAtIPC2IoIpHZo196FvxJ62rh8bu7YJ7c vidQ== X-Gm-Message-State: APjAAAU1t6P3o2uj9uqXaIIWTMgyVbcxzMTcrKFQyEcc6FJytcx/7xMd atGSxkGZ9VrDdM3Trdly1ks= X-Google-Smtp-Source: APXvYqwDlfmOtngNsOlIZgMmd4GovJcs/EwZwJTcPYLQ9UsRGTjEFKIL/Bityk4IMnS9q9dd8lTFqQ== X-Received: by 2002:a2e:994f:: with SMTP id r15mr7221092ljj.18.1572950204482; Tue, 05 Nov 2019 02:36:44 -0800 (PST) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id k19sm8809547ljg.18.2019.11.05.02.36.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2019 02:36:43 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.92.3) (envelope-from ) id 1iRwCZ-0001IL-3l; Tue, 05 Nov 2019 11:36:43 +0100 From: Johan Hovold To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, Johan Hovold Subject: [PATCH 1/3] USB: idmouse: simplify disconnect handling Date: Tue, 5 Nov 2019 11:36:36 +0100 Message-Id: <20191105103638.4929-2-johan@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191105103638.4929-1-johan@kernel.org> References: <20191105103638.4929-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Since commit d4ead16f50f9 ("USB: prevent char device open/deregister race") core prevents further calls to open() after usb_deregister_dev() returns so there's no need to use the interface data for synchronisation. This effectively reverts commit 54d2bc068fd2 ("USB: fix locking in idmouse") with respect to the open-disconnect race. Note that the driver already uses a present flag to suppress I/O post disconnect (even if all USB I/O take place at open). Signed-off-by: Johan Hovold --- drivers/usb/misc/idmouse.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/drivers/usb/misc/idmouse.c b/drivers/usb/misc/idmouse.c index 20b0f91a5d9b..0386bac224c4 100644 --- a/drivers/usb/misc/idmouse.c +++ b/drivers/usb/misc/idmouse.c @@ -60,7 +60,6 @@ static const struct usb_device_id idmouse_table[] = { USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, value, index, NULL, 0, 1000) MODULE_DEVICE_TABLE(usb, idmouse_table); -static DEFINE_MUTEX(open_disc_mutex); /* structure to hold all of our device specific stuff */ struct usb_idmouse { @@ -227,17 +226,13 @@ static int idmouse_open(struct inode *inode, struct file *file) if (!interface) return -ENODEV; - mutex_lock(&open_disc_mutex); /* get the device information block from the interface */ dev = usb_get_intfdata(interface); - if (!dev) { - mutex_unlock(&open_disc_mutex); + if (!dev) return -ENODEV; - } /* lock this device */ mutex_lock(&dev->lock); - mutex_unlock(&open_disc_mutex); /* check if already open */ if (dev->open) { @@ -280,14 +275,12 @@ static int idmouse_release(struct inode *inode, struct file *file) if (dev == NULL) return -ENODEV; - mutex_lock(&open_disc_mutex); /* lock our device */ mutex_lock(&dev->lock); /* are we really open? */ if (dev->open <= 0) { mutex_unlock(&dev->lock); - mutex_unlock(&open_disc_mutex); return -ENODEV; } @@ -296,11 +289,9 @@ static int idmouse_release(struct inode *inode, struct file *file) if (!dev->present) { /* the device was unplugged before the file was released */ mutex_unlock(&dev->lock); - mutex_unlock(&open_disc_mutex); idmouse_delete(dev); } else { mutex_unlock(&dev->lock); - mutex_unlock(&open_disc_mutex); } return 0; } @@ -379,7 +370,6 @@ static int idmouse_probe(struct usb_interface *interface, if (result) { /* something prevented us from registering this device */ dev_err(&interface->dev, "Unable to allocate minor number.\n"); - usb_set_intfdata(interface, NULL); idmouse_delete(dev); return result; } @@ -392,19 +382,13 @@ static int idmouse_probe(struct usb_interface *interface, static void idmouse_disconnect(struct usb_interface *interface) { - struct usb_idmouse *dev; - - /* get device structure */ - dev = usb_get_intfdata(interface); + struct usb_idmouse *dev = usb_get_intfdata(interface); /* give back our minor */ usb_deregister_dev(interface, &idmouse_class); - mutex_lock(&open_disc_mutex); - usb_set_intfdata(interface, NULL); /* lock the device */ mutex_lock(&dev->lock); - mutex_unlock(&open_disc_mutex); /* prevent device read, write and ioctl */ dev->present = 0; From patchwork Tue Nov 5 10:36:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11227487 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 A94031515 for ; Tue, 5 Nov 2019 10:36:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7D6CC21929 for ; Tue, 5 Nov 2019 10:36:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572950207; bh=/z23uh4jEDoqH6ANSqSlhXTR6f1qABmGqCzI/gayPwI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=e3WZTXeMNJm8WGBacUZ+dyjCj0DPwcLiOWi9rDZvMETibN+Efnq0VEs/a5bB4X0Bg edxBEt58wxiptCMAyPofKM6caLkEYyeUVmXDaj8ND0nvNn32lY+3VuiMaJfMtaKJk8 cne8mMgFCzs1XWdmp7kdHI28VsWw0+Sy/Ibs5yc0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388474AbfKEKgq (ORCPT ); Tue, 5 Nov 2019 05:36:46 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:36834 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388645AbfKEKgq (ORCPT ); Tue, 5 Nov 2019 05:36:46 -0500 Received: by mail-lj1-f195.google.com with SMTP id k15so9089674lja.3 for ; Tue, 05 Nov 2019 02:36:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1L1tHO+MLRZRW1I3nxunkX+/fAuMjMC2y7WnHBBiiN0=; b=tzHdiypfpB+AT52fFUUs78FD2rxvccjuAXeiNHcTKMuZT1H6a8/PrWcshSUBBFUJ2p 5l/mLJdKfJpXe2o+WETy3RD6vETFbIXSHz4Bs7PVLxOx4snPERHQMGDcVn0Nj7zSPpId UumfcZ9YEhmb5moNSu/fxKuxM7ql3wO4BC44IMZIL25i54ngmdmrIILDALPbzy0MB0j/ hKeHTWL/DUZtbIPj/9YBbek9ig65GHTPuDpcS3zOhTyV7gf7MMJnYNGsCGWDr9T+2EWL n967dx/ES2LHZOVLfwbcgw83T2af2q9yJaGkDJOK72iSDwz7fLq8f3myvMEtd0Vlce+V YH+A== X-Gm-Message-State: APjAAAUwU9vsUu4p2GiY+uu0X+XPKL9ncvtMNuSw2Gsu4r8bOZvlUZl0 XAJyQJ4ONd7gu9Cclw1QsNs= X-Google-Smtp-Source: APXvYqwCuNgtoAwjSfwZHefVtnRIdZWf2/P9COpAZISl1xnpaqJYyTXzBC+r508mo7lYnDIoId1o9g== X-Received: by 2002:a2e:c42:: with SMTP id o2mr18728178ljd.166.1572950204916; Tue, 05 Nov 2019 02:36:44 -0800 (PST) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id q124sm9094329ljb.28.2019.11.05.02.36.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2019 02:36:43 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.92.3) (envelope-from ) id 1iRwCZ-0001IP-6x; Tue, 05 Nov 2019 11:36:43 +0100 From: Johan Hovold To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, Johan Hovold Subject: [PATCH 2/3] USB: idmouse: drop redundant open-count check from release Date: Tue, 5 Nov 2019 11:36:37 +0100 Message-Id: <20191105103638.4929-3-johan@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191105103638.4929-1-johan@kernel.org> References: <20191105103638.4929-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The open count will always be exactly one when release is called, so drop the redundant sanity check. Signed-off-by: Johan Hovold --- drivers/usb/misc/idmouse.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/usb/misc/idmouse.c b/drivers/usb/misc/idmouse.c index 0386bac224c4..9b9d5df829d5 100644 --- a/drivers/usb/misc/idmouse.c +++ b/drivers/usb/misc/idmouse.c @@ -278,12 +278,6 @@ static int idmouse_release(struct inode *inode, struct file *file) /* lock our device */ mutex_lock(&dev->lock); - /* are we really open? */ - if (dev->open <= 0) { - mutex_unlock(&dev->lock); - return -ENODEV; - } - --dev->open; if (!dev->present) { From patchwork Tue Nov 5 10:36:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11227491 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 AE49314E5 for ; Tue, 5 Nov 2019 10:36:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8CFD321929 for ; Tue, 5 Nov 2019 10:36:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572950209; bh=TCYFRzScqNRePzptO0n2J5h/AVHCH81pGioJ2dMKmGU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=g7bIWjO1sjXFHv1jCe5B1DcB+n/5p8SoVgPbvRby34AeGQ1xT8r4T28Z5Z7tkaQsh Rt+WziLJ4HqSMN2xs5qgb7F4aFqNN4iM60utQhG+yHiG547kl5Ep4JtmS9bVQLvAEN xfDnbxpWwyoy1IYEHbAtxSJAA7js0MpyGy2NBjlw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388759AbfKEKgs (ORCPT ); Tue, 5 Nov 2019 05:36:48 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:41443 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388695AbfKEKgs (ORCPT ); Tue, 5 Nov 2019 05:36:48 -0500 Received: by mail-lf1-f65.google.com with SMTP id j14so14706109lfb.8 for ; Tue, 05 Nov 2019 02:36:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IKV85RxvHyY4pFWFHgYAEhT0nXOYN14ot7DMiLlwbhY=; b=nfq8XfvjctiD/Q9985dQ0rbj1jXJMPuIdhtBmY7picB9yOvXW9f0E/wNi4MXFtX0lJ b5l46XO90Tqw621cu/tviKWjRBU051DzoFnGRKfknwg3/+LVeM99paIFomRmXndZDJA6 gQB0QZL0Kgcn6Dj7sAWdLmjCdp6Omel4oeIRZN0K0EBicHZmJlnUpN3SQzxDlnN8CrIN Laa/SWMYgxwuwO/zk4i1bxjUtIUtksamec06CMmdX7tup89+T5vIW4TNJ43hMNDBYY5v eaMKNvoJAnPPGgl4u3jmbH0VHWmd9ePaEjWkNfWRAIyZ20BA/brGNi4eZr74br66XhNF /PxQ== X-Gm-Message-State: APjAAAWWyjchDGW3TPZgwMCSSDoU/kYi46tm/45RXJhfC5Sh2juEsIzG gudGB89qwF650C/qDzdyzZs= X-Google-Smtp-Source: APXvYqx7AHCv3/M2NZli90sLj0EJ6yPWAqHry3LPESPGyXWX22ex2K0Kdyl3McABJGEwMpvhGeBvLg== X-Received: by 2002:a19:a40c:: with SMTP id q12mr7865413lfc.65.1572950205502; Tue, 05 Nov 2019 02:36:45 -0800 (PST) Received: from xi.terra (c-51f1e055.07-184-6d6c6d4.bbcust.telenor.se. [85.224.241.81]) by smtp.gmail.com with ESMTPSA id k19sm8809567ljg.18.2019.11.05.02.36.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2019 02:36:43 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.92.3) (envelope-from ) id 1iRwCZ-0001IU-AA; Tue, 05 Nov 2019 11:36:43 +0100 From: Johan Hovold To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, Johan Hovold Subject: [PATCH 3/3] USB: idmouse: clean up runaway white space Date: Tue, 5 Nov 2019 11:36:38 +0100 Message-Id: <20191105103638.4929-4-johan@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191105103638.4929-1-johan@kernel.org> References: <20191105103638.4929-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Drop space between function identifiers and opening parenthesis, which was no longer even used consistently within the driver. Signed-off-by: Johan Hovold --- drivers/usb/misc/idmouse.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/usb/misc/idmouse.c b/drivers/usb/misc/idmouse.c index 9b9d5df829d5..4afb5ddfd361 100644 --- a/drivers/usb/misc/idmouse.c +++ b/drivers/usb/misc/idmouse.c @@ -56,7 +56,7 @@ static const struct usb_device_id idmouse_table[] = { #define FTIP_SCROLL 0x24 #define ftip_command(dev, command, value, index) \ - usb_control_msg (dev->udev, usb_sndctrlpipe (dev->udev, 0), command, \ + usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), command, \ USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, value, index, NULL, 0, 1000) MODULE_DEVICE_TABLE(usb, idmouse_table); @@ -157,8 +157,8 @@ static int idmouse_create_image(struct usb_idmouse *dev) /* loop over a blocking bulk read to get data from the device */ while (bytes_read < IMGSIZE) { - result = usb_bulk_msg (dev->udev, - usb_rcvbulkpipe (dev->udev, dev->bulk_in_endpointAddr), + result = usb_bulk_msg(dev->udev, + usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr), dev->bulk_in_buffer + bytes_read, dev->bulk_in_size, &bulk_read, 5000); if (result < 0) { @@ -222,7 +222,7 @@ static int idmouse_open(struct inode *inode, struct file *file) int result; /* get the interface from minor number and driver information */ - interface = usb_find_interface (&idmouse_driver, iminor (inode)); + interface = usb_find_interface(&idmouse_driver, iminor(inode)); if (!interface) return -ENODEV; @@ -246,7 +246,7 @@ static int idmouse_open(struct inode *inode, struct file *file) result = usb_autopm_get_interface(interface); if (result) goto error; - result = idmouse_create_image (dev); + result = idmouse_create_image(dev); usb_autopm_put_interface(interface); if (result) goto error;