From patchwork Thu Dec 11 12:51:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Wu X-Patchwork-Id: 5475871 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 92AAA9F1CD for ; Thu, 11 Dec 2014 12:53:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CBA0D20160 for ; Thu, 11 Dec 2014 12:52:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E994920149 for ; Thu, 11 Dec 2014 12:52:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932480AbaLKMw5 (ORCPT ); Thu, 11 Dec 2014 07:52:57 -0500 Received: from lekensteyn.nl ([178.21.112.251]:45678 "EHLO lekensteyn.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932882AbaLKMve (ORCPT ); Thu, 11 Dec 2014 07:51:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lekensteyn.nl; s=s2048-2014-q3; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=1J0iMVoA3/Rho1vTdb+cm4jbqKVWqFMLlyysQP1SN/s=; b=R2L6TJoE7Qmf2dcTluAOY90AXBaV+mXW7WhfSgN1Jso5aXk4+ms4CI6sYWc9QrVt/zgt2dnZKrQuCQHzLLJxcfah0wtSaki1LIBbJUJwH1pgFFt2Csee7f01mQMV4gCC9obF0+cPos1C0tecBkRDeDfX2d5s1X/PoaMn9ZCJOU9Zu1guda03ShtGDmkUf3ZIHE8vZssMGvcc1CL5HoCU6g3G0/TnsJBvh4SvuRoWwRc1nMom2yOxhM7pQzc2qO5G7YWJLMfVI+GrcoeW8cOw+3Ft0wxAtRM38pM6q22AWpNelVArrKXdsrYTPW/LDav1pkoX6ET9MTLGkRAIk4ADfw==; Received: by lekensteyn.nl with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA256:128) (Exim 4.80) (envelope-from ) id 1Xz3DI-00020h-E5; Thu, 11 Dec 2014 13:51:24 +0100 From: Peter Wu To: Benjamin Tissoires , Jiri Kosina , Nestor Lopez Casado , Andrew de los Reyes Cc: Peter Hutterer , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] HID: logitech-hidpp: disable io in probe error path Date: Thu, 11 Dec 2014 13:51:20 +0100 Message-Id: <1418302280-14794-5-git-send-email-peter@lekensteyn.nl> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1418302280-14794-1-git-send-email-peter@lekensteyn.nl> References: <1418302280-14794-1-git-send-email-peter@lekensteyn.nl> X-Spam-Score: -0.0 (/) X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Balance a hid_device_io_start() call with hid_device_io_stop() in the error path. This avoids processing of HID reports when the probe fails which possibly leads to invalid memory access in hid_device_probe() as report_enum->report_id_hash might already be freed via hid_close_report(). hid_set_drvdata() is called before wtp_allocate, be consistent and clear drvdata too on the error path of wtp_allocate. Signed-off-by: Peter Wu Reviewed-by: Benjamin Tissoires --- Hi Andrew, There are few users of hid_device_io_start/stop, this is the first one to get start/stop out of sync. Should the comment of hid_device_io_start() be updated to ensure that hid_device_io_stop() gets called before probe() returns? Or should the hid-core be changed to handle this out-of-sync issue: if (ret) { if (hdev->io_started)) down(&hdev->driver_input_lock); hid_close_report(hdev); hdev->driver = NULL; } Is my observation correct or not that HID reports can arrive during hid_close_report() when io_started == true? Kind regards, Peter --- drivers/hid/hid-logitech-hidpp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 4292cc3..2f420c0 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -1121,7 +1121,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) { ret = wtp_allocate(hdev, id); if (ret) - return ret; + goto wtp_allocate_fail; } INIT_WORK(&hidpp->work, delayed_work_cb); @@ -1141,6 +1141,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) if (id->group != HID_GROUP_LOGITECH_DJ_DEVICE) { if (!connected) { hid_err(hdev, "Device not connected"); + hid_device_io_stop(hdev); goto hid_parse_fail; } @@ -1186,6 +1187,7 @@ hid_hw_start_fail: hid_parse_fail: cancel_work_sync(&hidpp->work); mutex_destroy(&hidpp->send_mutex); +wtp_allocate_fail: hid_set_drvdata(hdev, NULL); return ret; }