From patchwork Wed Nov 23 22:07:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roderick Colenbrander X-Patchwork-Id: 9444409 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9334D60235 for ; Wed, 23 Nov 2016 22:08:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D906271CB for ; Wed, 23 Nov 2016 22:08:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8246C27D7F; Wed, 23 Nov 2016 22:08:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3621D27D76 for ; Wed, 23 Nov 2016 22:08:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933795AbcKWWIK (ORCPT ); Wed, 23 Nov 2016 17:08:10 -0500 Received: from mail-yw0-f169.google.com ([209.85.161.169]:35788 "EHLO mail-yw0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932758AbcKWWIJ (ORCPT ); Wed, 23 Nov 2016 17:08:09 -0500 Received: by mail-yw0-f169.google.com with SMTP id i145so23765708ywg.2 for ; Wed, 23 Nov 2016 14:08:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaikai-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6o7f1ZX58qD3S+uG6Aw3LIsree3H5fXizZJgakkCLfA=; b=G6GDa/bGfWpMpqN2X7W0IKkt3m702GRosE4iu7+1Hw1bJnvAJqgg0fVvq46SBSlTeL 16lTc6raVv2hc3fPdGX3KqjqIkXs1t82d9BlfzhH6BPEyJCde/3SqQ7oF/CJFTHJVqzL nhvHevJRIKh8o17DwcXeuypp2fMVPGpzqhqU42uLGkzl7c6tOdSADbe8McIQBFL6k/9e J2pCiI6kjGueCSKQbo1t1vwzBAvR0uvNw+AVTnRBTVl3bJdDwfF7VurMCZFQaiCDJv29 1VtBvTJQR/oswf7YA0MsK941Ed/4VklHeW7HZ4JU4jSYAjBu44zfJzCOYviB09ck2LPR SgZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6o7f1ZX58qD3S+uG6Aw3LIsree3H5fXizZJgakkCLfA=; b=PizfYN6zA9NwYIDtcH0uMVUKbaRKvRfe+ISLvih4vz45r4EM8hw1Vv91uPJbx4Hoyq 3V0aAmoNDV3/K6H8HjRB8EE0ZVHHqw0D7AcTS3eje6hLHLfogLfH9JINwpl+m4vrOyQs cgdyub4wOibHVh4a0jyCg4zIT+hitGpN8GG/VxmLx56rpovZn6TXSLXAmFCfDDEjlVqv T12eYCDDOLQVGMEHyF1NbaqXVulKvZfHegC2XJgjKlMf1zSJlfRwTVzYsRNED+tMAgu/ JRL+KCyFJ6JpNAiVNM119d3QHPcYZCNizHoniylMiNo4Pbi/+rh5aSG/q6q/jOhMQSPu Lw+A== X-Gm-Message-State: AKaTC00QoaiojStFxpTtrkNh5WMXnPKIpGZjYJjvwqpaxLkH8imB/azK3m7A917btokVCsHM X-Received: by 10.129.74.85 with SMTP id x82mr5863149ywa.219.1479938889056; Wed, 23 Nov 2016 14:08:09 -0800 (PST) Received: from konan1.dev.biz ([100.42.98.197]) by smtp.gmail.com with ESMTPSA id u134sm12154004ywg.31.2016.11.23.14.08.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Nov 2016 14:08:08 -0800 (PST) From: Roderick Colenbrander To: linux-input@vger.kernel.org Cc: Dmitry Torokhov , Jiri Kosina , Benjamin Tissoires , Simon Wood , Frank Praznik , Tim Bird , Roderick Colenbrander Subject: [PATCH 1/8] HID: sony: Fix memory issue when connecting device using both Bluetooth and USB Date: Wed, 23 Nov 2016 14:07:06 -0800 Message-Id: <1479938833-26424-2-git-send-email-roderick@gaikai.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1479938833-26424-1-git-send-email-roderick@gaikai.com> References: <1479938833-26424-1-git-send-email-roderick@gaikai.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Roderick Colenbrander A previous patch moved most input initialization from sony_probe to sony_input_configured to avoid some race conditions. The driver has some special logic to prevent the device to get registered twice in case the user connects it both over Bluetooth and USB. When this condition happens sony_input_configured returns a failure, but sony_probe continues as hid_hw_start doesn't fail. As was discussed on linux-input, it is acceptable for this function to fail. This patch adds a check for the HID_CLAIMED_INPUT flag within sony_probe to determine whether initialization succeeded correctly. The flag is not set by the HID layer when sony_input_configured fails. Signed-off-by: Roderick Colenbrander --- drivers/hid/hid-sony.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index 14763cd..3385006 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -2524,6 +2524,19 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) return ret; } + /* sony_input_configured can fail, but this doesn't result + * in hid_hw_start failures (intended). Check whether + * the HID layer claimed the device else fail. + * We don't know the actual reason for the failure, most + * likely it is due to EEXIST in case of double connection + * of USB and Bluetooth, but could have been due to ENOMEM + * or other reasons as well. + */ + if (!(hdev->claimed & HID_CLAIMED_INPUT)) { + hid_err(hdev, "failed to claim input\n"); + return -ENODEV; + } + return ret; }