From patchwork Thu Mar 14 05:24:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kangjie Lu X-Patchwork-Id: 10852157 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 9DA751575 for ; Thu, 14 Mar 2019 05:24:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FAB929C44 for ; Thu, 14 Mar 2019 05:24:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73BD729D42; Thu, 14 Mar 2019 05:24:23 +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 1A18729D44 for ; Thu, 14 Mar 2019 05:24:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726130AbfCNFYQ (ORCPT ); Thu, 14 Mar 2019 01:24:16 -0400 Received: from mta-p6.oit.umn.edu ([134.84.196.206]:59780 "EHLO mta-p6.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726206AbfCNFYM (ORCPT ); Thu, 14 Mar 2019 01:24:12 -0400 Received: from localhost (unknown [127.0.0.1]) by mta-p6.oit.umn.edu (Postfix) with ESMTP id 9696BC65 for ; Thu, 14 Mar 2019 05:24:10 +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 4rA1UpLA8gUh for ; Thu, 14 Mar 2019 00:24:10 -0500 (CDT) Received: from mail-it1-f200.google.com (mail-it1-f200.google.com [209.85.166.200]) (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 6A583603 for ; Thu, 14 Mar 2019 00:24:10 -0500 (CDT) Received: by mail-it1-f200.google.com with SMTP id h3so3643827itb.4 for ; Wed, 13 Mar 2019 22:24:10 -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=ijSfNicS7SkNZfR/waD6KTfAoFyPyUvljJrd8v/Py/Q=; b=QWbGWtn0IM9M1eVQTT/Gw5EUWIlWLKlJTKkXp3FLF4nMDq0NmUqmayntg8LVaBAFKd kTihqCsipRQMhRGno5FElfANq/eZ1aOkpFEtcYR9Pg7jTrnMxrIHKNte/zdUmbsil8eO c6Bghu0j7tdiPlJAgEaPyaBge7l+oY1XDL248f9lwh7hgfJMOhAjGmDxq3eNR23/rndA V2o1e/nqAs5wf5oS6+vMn4CfcFnZI4PL0Mmv8OSFNi8VfcVYaTukBgymjJUBCZUX2+iv 24esL/IKILT2LbwgXuP8vBIE83BFKT+zi7WT0woMeFANOgYj1eX5FEFOHU0OYoAT63Qi dRXA== 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=ijSfNicS7SkNZfR/waD6KTfAoFyPyUvljJrd8v/Py/Q=; b=TKH2Ysj1OspIInfCg8YTOiVKddvnzk5Xxi4Am1tHjnNuGTsdTj56mYC5GAdJKuumMe dykgDq74GbT4JwOJSRBx+2rPPAXm6BaHcYwsPOVLpFhD1fqs5ZgRhP+wPkaKwM5OzPUK jBeRHUu3QpT1NS6fgOz989CdCrO7tIycc7fgtTr5+qsC9DMAtVGMMcCZALKdxk+JvjVB JJg5atUbM+sjB68O1XjdXYwDhx/cl1tn65ZVIJeBvga6OYaqh3H+bId+JQuTEX1hO8/W 2MscN+gS5pcs+L5zJbPLvwZoVMXzx9z1o45+PejsXyrT1loH7P9LW4Aq/JrrxELXnKFf 8sYg== X-Gm-Message-State: APjAAAX+DP0kwmhjfV81qkQXS4aJwBie21dfY0cVMIBzFpV4LsYQzeKu ihc1FlGZkKMk8DmAj/7kCdk/ghjvePTZuWwVrHBSaJ+n4mAYjvQ114J3FSS2CkaW2XCdhif+fEg 15EDnEn954WJmU6raumek3Fel50c= X-Received: by 2002:a02:6341:: with SMTP id j62mr8263322jac.27.1552541050013; Wed, 13 Mar 2019 22:24:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqzdR0+YMP/Fw8LwFRspcHb7U98b3dTDkUYuXQfPpmZd44SVxCkH0cTlcc9H4aW81Pb8QdYADg== X-Received: by 2002:a02:6341:: with SMTP id j62mr8263310jac.27.1552541049780; Wed, 13 Mar 2019 22:24:09 -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 f132sm5948292ioa.76.2019.03.13.22.24.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Mar 2019 22:24:08 -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 v3] hid: logitech: check the return value of create_singlethread_workqueue Date: Thu, 14 Mar 2019 00:24:02 -0500 Message-Id: <20190314052402.31448-1-kjlu@umn.edu> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190312100233.106098c8@lwn.net> References: <20190312100233.106098c8@lwn.net> 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. --- V3: do not introduce memory leaks. Signed-off-by: Kangjie Lu --- drivers/hid/hid-logitech-hidpp.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 15ed6177a7a3..0a243247b231 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -2111,6 +2111,13 @@ static int hidpp_ff_init(struct hidpp_device *hidpp, u8 feature_index) kfree(data); return -ENOMEM; } + data->wq = create_singlethread_workqueue("hidpp-ff-sendqueue"); + if (!data->wq) { + kfree(data->effect_ids); + kfree(data); + return -ENOMEM; + } + data->hidpp = hidpp; data->feature_index = feature_index; data->version = version; @@ -2155,7 +2162,6 @@ static int hidpp_ff_init(struct hidpp_device *hidpp, u8 feature_index) /* 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 */