From patchwork Thu Sep 4 07:02:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Kosina X-Patchwork-Id: 4842981 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7AD299F314 for ; Thu, 4 Sep 2014 07:02:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E3BDE20219 for ; Thu, 4 Sep 2014 07:02:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0AA03200D0 for ; Thu, 4 Sep 2014 07:02:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751184AbaIDHCN (ORCPT ); Thu, 4 Sep 2014 03:02:13 -0400 Received: from cantor2.suse.de ([195.135.220.15]:49980 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751068AbaIDHCN (ORCPT ); Thu, 4 Sep 2014 03:02:13 -0400 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 93198AC31; Thu, 4 Sep 2014 07:02:11 +0000 (UTC) Date: Thu, 4 Sep 2014 09:02:10 +0200 (CEST) From: Jiri Kosina To: Dylan Alex Simon cc: Benjamin Tissoires , Vivien Didelot , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] HID: thingm: fix workqueue race on remove In-Reply-To: <20140904010519.GA13189@datura.dylex.net> Message-ID: References: <54062150.2010800@gmail.com> <20140903023531.GA1128@datura.dylex.net> <20140903081723.GA1153@datura.dylex.net> <20140903130348.GA1161@datura.dylex.net> <20140903141601.GA1866@datura.dylex.net> <20140904010519.GA13189@datura.dylex.net> User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP thingm_remove_rgb() needs to flush the workqueue after all the LED classes have been unregistered, otherwise the removal might race with another LED event coming, causing thingm_led_set() to schedule additional work after thingm_remove_rgb() has flushed it. This obviously causes oops later, as the scheduled work has been freed in the meantime. In addition to that, move the hid_hw_stop() to an earlier place, so that dmesg is not polluted by failure messages about not being able to write the LED while the device is being shut down. Reported-and-tested-by: Dylan Alex Simon Signed-off-by: Jiri Kosina --- Queued in hid.git#for-3.18/upstream drivers/hid/hid-thingm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-thingm.c b/drivers/hid/hid-thingm.c index 134be89..f206398 100644 --- a/drivers/hid/hid-thingm.c +++ b/drivers/hid/hid-thingm.c @@ -208,10 +208,10 @@ unregister_red: static void thingm_remove_rgb(struct thingm_rgb *rgb) { - flush_work(&rgb->work); led_classdev_unregister(&rgb->red.ldev); led_classdev_unregister(&rgb->green.ldev); led_classdev_unregister(&rgb->blue.ldev); + flush_work(&rgb->work); } static int thingm_probe(struct hid_device *hdev, const struct hid_device_id *id) @@ -286,10 +286,10 @@ static void thingm_remove(struct hid_device *hdev) struct thingm_device *tdev = hid_get_drvdata(hdev); int i; + hid_hw_stop(hdev); + for (i = 0; i < tdev->fwinfo->numrgb; ++i) thingm_remove_rgb(tdev->rgb + i); - - hid_hw_stop(hdev); } static const struct hid_device_id thingm_table[] = {