From patchwork Tue Mar 12 06:16:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kangjie Lu X-Patchwork-Id: 10848609 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 671C614DE for ; Tue, 12 Mar 2019 06:16:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4965028448 for ; Tue, 12 Mar 2019 06:16:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C53C294F0; Tue, 12 Mar 2019 06:16:56 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 53EE628448 for ; Tue, 12 Mar 2019 06:16:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726705AbfCLGQx (ORCPT ); Tue, 12 Mar 2019 02:16:53 -0400 Received: from mta-p6.oit.umn.edu ([134.84.196.206]:51212 "EHLO mta-p6.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725855AbfCLGQx (ORCPT ); Tue, 12 Mar 2019 02:16:53 -0400 Received: from localhost (unknown [127.0.0.1]) by mta-p6.oit.umn.edu (Postfix) with ESMTP id 0C54DB32 for ; Tue, 12 Mar 2019 06:16:52 +0000 (UTC) X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p6.oit.umn.edu ([127.0.0.1]) by localhost (mta-p6.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id a6ugO3Tvtn_D for ; Tue, 12 Mar 2019 01:16:51 -0500 (CDT) Received: from mail-it1-f198.google.com (mail-it1-f198.google.com [209.85.166.198]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mta-p6.oit.umn.edu (Postfix) with ESMTPS id CD6CAA13 for ; Tue, 12 Mar 2019 01:16:51 -0500 (CDT) Received: by mail-it1-f198.google.com with SMTP id a184so1046828itc.0 for ; Mon, 11 Mar 2019 23:16:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umn.edu; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/iMNiJvfEscsi58jKgoeUADcaa6upF9XiWwfnWbBtSg=; b=gMLEjxwp9VC5wOoH+FEHXOF799h6e4TOQXgsJkkJXCMMPF50e6hp5NJY686kGaiBGw cWAHuWyo0IOz5bJ/m9S5AMgJk1rDvqHrw9kODDp87UW6oA6NTOJLl6K33R7cjlgMOada 6/fwtFIFoRu9x7cq6YIo4Z9E/DB2DEfnE7D6Julq3+22AbmkjEZqA6vZ1A4SLqZCu4KS EiRBWbrZ3h7fNdFWIBD22VONRp8/aReneQcnV4Wc5TXYqcLP+Lz9DtKzTtqC2UhfFg53 Tzpk1erq0jlOZMDNPZ4zRL1EUQl3Tapq/hSUqRXlhmgJSdCXkCLqil8huo1OM5u5OFSO 8SQg== 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; bh=/iMNiJvfEscsi58jKgoeUADcaa6upF9XiWwfnWbBtSg=; b=B8jrDx983lmLB+FCcSKr5BxbS3ivezKjnEYVMawravY/3BA8u8bwd1QIrXNSTezzPW 4df28x2BngFcekN/zgFbcMSRwtdf0LBfBXYa8KJdTEtSKtag/zVKf6Ie+eAe8jlwRdas ymfLw7dxgHbBA/4oC+6sSxoO0kwbVu55jLZlR+uu1lWkPdDflE/BWKCpMWPZPgHcyI+5 F0giLaUVMVZgY0ByhmjNhzrxkZmz5PbWa4FhSeh9merQEygfdh6x6ngN9MI9ofHgnx2d az0psf2od6ckMg8YmXY33z4Gx1pSYvpvzbQP9j3veuRFysj3Ia7dci0OWu52TiXTlVtV wxZQ== X-Gm-Message-State: APjAAAUswUAEOuVPihSPa/RS85tseAVCkK5RAClhSpfjfEEQt1p4D+Ds FawydwCi34NrXxKjt0p6ZhAqD3nFS3+IA0uCjFO/CCzsxX821Yhws6qHvNVtEyEnKWC00OcqCM4 CZoY0RVnAhB7VyFREaNGHCRD0nbo= X-Received: by 2002:a02:660e:: with SMTP id k14mr20460851jac.34.1552371411417; Mon, 11 Mar 2019 23:16:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqzOvYXxmfTmxihR8aYpzT8CwZJj0t8G9koKU38XFrwh38WgcFvImiJg9A4u9D8BZjjjqy3GaA== X-Received: by 2002:a02:660e:: with SMTP id k14mr20460843jac.34.1552371411118; Mon, 11 Mar 2019 23:16:51 -0700 (PDT) Received: from bee.dtc.umn.edu (cs-bee-u.cs.umn.edu. [128.101.106.63]) by smtp.gmail.com with ESMTPSA id d135sm848697itd.43.2019.03.11.23.16.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Mar 2019 23:16:50 -0700 (PDT) From: Kangjie Lu To: kjlu@umn.edu Cc: pakki001@umn.edu, Jiri Kosina , Benjamin Tissoires , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] hid: logitech: check the return value of create_singlethread_workqueue Date: Tue, 12 Mar 2019 01:16:28 -0500 Message-Id: <20190312061628.13869-1-kjlu@umn.edu> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: 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 create_singlethread_workqueue may fail and return NULL. The fix checks if it is NULL to avoid NULL pointer dereference. Also, the fix moves the call of create_singlethread_workqueue earlier to avoid resource-release issues. Signed-off-by: Kangjie Lu --- drivers/hid/hid-logitech-hidpp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 15ed6177a7a3..1b7c336cae6d 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -2106,6 +2106,12 @@ static int hidpp_ff_init(struct hidpp_device *hidpp, u8 feature_index) data = kzalloc(sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; + + /* init the hardware command queue */ + data->wq = create_singlethread_workqueue("hidpp-ff-sendqueue"); + if (!data->wq) + return -ENOMEM; + data->effect_ids = kcalloc(num_slots, sizeof(int), GFP_KERNEL); if (!data->effect_ids) { kfree(data); @@ -2154,8 +2160,6 @@ static int hidpp_ff_init(struct hidpp_device *hidpp, u8 feature_index) data->gain = error ? 0xffff : get_unaligned_be16(&response.fap.params[0]); /* ignore boost value at response.fap.params[2] */ - /* init the hardware command queue */ - data->wq = create_singlethread_workqueue("hidpp-ff-sendqueue"); atomic_set(&data->workqueue_size, 0); /* initialize with zero autocenter to get wheel in usable state */