From patchwork Mon Sep 18 11:54:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rahul Rameshbabu X-Patchwork-Id: 141488 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2821767vqi; Mon, 18 Sep 2023 10:19:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4Gny0PrXSvGS81DZZl33zutHEQ1y01YfbtsRdNzQ5BjITc75LYN+n4LgFnnT9l6g3LBR/ X-Received: by 2002:a05:6a20:12ce:b0:153:a897:3be7 with SMTP id v14-20020a056a2012ce00b00153a8973be7mr10968098pzg.15.1695057549530; Mon, 18 Sep 2023 10:19:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1695057549; cv=pass; d=google.com; s=arc-20160816; b=twGBe6n/E2PWglB5B6R8Wtas4rqJvoVkv68vf8TnE3o+HbWoEKUP9Mn06NriJMD0Jy N2I/rLUi/HkqhdbeT9aneBrbWhkNel1efRV2PCmGtinAkcdQ7mTm912jeDb/CMl2gKX3 U7lDN+qxXephVIhbRYuKMotj0OMmiF0hFzT7Laqpglj4wpqxg9sEZa6pgBCLIjsjKPWn WNfunMToiZ3OSkkJkgCv2aK/JrR4HpRPiWuz+gG4J1RF7Fn9Lml/MRkeDoRFHlV52f7F IiZ8A7D5WQ1HkyXg+F1dROXQRx8HAkdz1nl6sFZ/0jCRHOvWLRJsA/nV0E7JvBljLZL+ YWJw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=aeb7NXPu+SVpuJcq0GnojPrdoC4Ed6o8r6TYXWxu18c=; fh=SikQoJLNpGF0HeiQJkcbVWYlrNXIBKXrenHYWqn1frM=; b=QoMuSkWYeBELU5qu1pu6rJMKyaiLzxcb/QQJjmkljNE6L0S/3Na3R7b1A842XQihoi aoSYk2ltx8j641hLVKFN4GD7AJgU3gFEfdqd9hJWJmsokScrJ/+wNHwAbLL8wN/fEbjA cf52yMe14GUOXJxL2a1uEOeSUmKY5DX+aM/zDi3xcNdo5smeIyZanBKqc52GmFh0Oumi a6hMRAPeZ29s5H0oXO4hWJpHZM/am7OibX9bYiYkwGG/j3KDpE+tbvSzKVhLDBKe4nmD cOdxzNzK/CQJaZ8VGczttU+apAg9pty4el6lrgqGK2g0WbZ47ya/+5P0e2tiaQhxuXeH I0Xg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=JH6Ktx8p; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id k14-20020a056a00134e00b0068fa57d2442si8487057pfu.130.2023.09.18.10.19.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 10:19:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=JH6Ktx8p; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 2C815809C388; Mon, 18 Sep 2023 04:56:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241688AbjIRL4W (ORCPT + 27 others); Mon, 18 Sep 2023 07:56:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241346AbjIRLzv (ORCPT ); Mon, 18 Sep 2023 07:55:51 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2040.outbound.protection.outlook.com [40.107.92.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C64EA10F; Mon, 18 Sep 2023 04:54:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Exz7EGtXsNfBwM1pdmIOZ3TDbuuwshfb4keJsaTKoNaNrE3PVIJYZq9wbsrLEy84f5rZC3oJugBg2pQ9F4XZKSARoRmm/KPnd6P1FT6ud4MDMFd0YMZmc9TEJTB/GoYZwX3m2C1fvlIa+ouh52hrkY4XSeiXd94azr7bn3KnUncDUt9EgSrbD2ov9bPtjgFjjtHwAY0au81V8hhCXRjPGCFtHLpDvurX02o3Lc6ZbmsPNoJv+VzGFBSKMzbCjOVvZRIVdC+u1FEWTow2VuIU6G3gq2LJiRaF9YVAyGn0LgqnRXF9LjJO2xmWt3CpR+9QULQeWoj2e6BzV3YBpgHI9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aeb7NXPu+SVpuJcq0GnojPrdoC4Ed6o8r6TYXWxu18c=; b=Okli5iyhrTaTKmMd9Ha1D876VKvV8Pqe0uNdv7t7fPBAC191iLWr5G0Luhb+1b24LjLo6a+UcdNg7E2dmLnvnI8g5u4itJa7pcy6Oy29ZRNeWNsKM3ZFxcMtVm7Ohrsp3I+sk0gENe2gYoMlQmRH9wO0EWwUlIWCBgNpSP/3Pot+iE/S63xsUijgY06JdaStZUe31K1c5aOIOpyIMzpL0SF2gnYlANtIv2/SKiCs2NmXF4ejpAqpaPFb8cENfp7zsihqFtm9mKjBq9uI1jxHYrN++Vyb8rpefA40cJuq+LfBnGp4h13GSnIDgaL6oM2yl+kWH1IE+t8jws250qwOfw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aeb7NXPu+SVpuJcq0GnojPrdoC4Ed6o8r6TYXWxu18c=; b=JH6Ktx8pJmekqwJwZBDzSxZAhlIgMz1W3ZkJnLSDu4TWnCDFQChDEmHGdLqIRHwxos5qvDYIvrzIXgqV10EXZa/LnOyIiybsG5bs43FrwDHF11+LNz0oA97OZJTrU6AOOxgQ8QBs0huWxRNgGwp5lkwW0U2RssYBWYJp51p//veNqLwQ54u7NT9s8ql3hNxydxtZ1JJ8RP+edcWgyVPhKtpSYfGdx1qUG4OLc48ZUapgAB09qSmc6kU3Iw6nnlIQM8vhz19BeIxRS222N5jCLYz7+dreKqXngYbek0uljFy9iTNOCd+KHRQmCoelBTJrpv5JLzqRD7+MI7TB5p5FPw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BYAPR12MB2743.namprd12.prod.outlook.com (2603:10b6:a03:61::28) by DS0PR12MB9346.namprd12.prod.outlook.com (2603:10b6:8:1be::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.27; Mon, 18 Sep 2023 11:54:50 +0000 Received: from BYAPR12MB2743.namprd12.prod.outlook.com ([fe80::5cc1:1ea3:4ec5:72af]) by BYAPR12MB2743.namprd12.prod.outlook.com ([fe80::5cc1:1ea3:4ec5:72af%5]) with mapi id 15.20.6792.026; Mon, 18 Sep 2023 11:54:50 +0000 From: Rahul Rameshbabu To: Jiri Kosina , Benjamin Tissoires Cc: Christophe JAILLET , kernel-janitors@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Rahul Rameshbabu Subject: [PATCH v3 3/3] HID: nvidia-shield: Introduce thunderstrike_destroy() Date: Mon, 18 Sep 2023 04:54:32 -0700 Message-Id: <20230918115432.30076-4-rrameshbabu@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230918115432.30076-1-rrameshbabu@nvidia.com> References: <20230918115432.30076-1-rrameshbabu@nvidia.com> X-ClientProxiedBy: BY3PR05CA0002.namprd05.prod.outlook.com (2603:10b6:a03:254::7) To BYAPR12MB2743.namprd12.prod.outlook.com (2603:10b6:a03:61::28) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR12MB2743:EE_|DS0PR12MB9346:EE_ X-MS-Office365-Filtering-Correlation-Id: 9c6d9c14-6bba-4e28-5d86-08dbb83e1036 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CREfAjYvumeXMZoZQ1mp5W21Cif+fDm3hvDmcyoHxjUSWeB+pBzM6GR5EuA5IZEAvG3xlXcyZJnBLG2S/5RtjBBE7nHsToZMAUJAsoDFMTprYkv5ED0fuTbRMrLME8X604vUkp788lTL7fVJ80oBTE3kfSpuTqOiYwNPyZRrVLsvi0sMVI68vTWvSF8FzxfKWnBLRPHL6kWQYLD0WEZAqn67wCu4/PtB/1lEcBkBYPjL9PuYBqFc580H3Xl1Kz0LdalIFtmc8rZUnuYOCAVMdE01kAqNZXTJiIje6EwLwuWQpcPPiKXtLf0M4QCDURDlhPWzihnjMi1Dqd3RWnpZNL40XHtB4P1xES5p1jsZ5SVeuSSILpMW35aRNvAAvW5exEwEVG7revOsNImYVh4BBx+RuSN+R12odMcwHo1hL9jNzJSyh+S7NT0TOIIoPddvyIRXkiF6yGidmFjsM9bvWKzNRejRsynv9vZqZssrgiKKUaYKYNQOygJ3+PMGMnJdKz2WGXPwVQrDEP2Rymvn8OjVH+hP2oSiKm32ToJHG8bH2XkDqPWe5l4dZuiriw6v X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR12MB2743.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(39860400002)(366004)(136003)(376002)(346002)(186009)(1800799009)(451199024)(6486002)(6506007)(6512007)(6666004)(83380400001)(86362001)(38100700002)(36756003)(107886003)(2616005)(1076003)(26005)(316002)(41300700001)(8936002)(8676002)(4326008)(2906002)(66946007)(54906003)(66476007)(66556008)(110136005)(478600001)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1Y6Aa8yCZiwDRtjc3+iOaMyrJPO6Enssffq9KPmpjlskIpiD4zAYPl9Q0PrKGkii5eNrp4/4s7XTOBprjmhPxB9RmMWiwa0+llmVXW7jqm/y0bPPs+ijRzyWPA+nulU4PQlpo5D/sbz9iAOfhHliZ6idfCQQPCKcmiMmCIEBWkiOJAQ5bl4nOkwoxowKgJRkgGFenCuUvY+xRU5eQy6WufPxx7LhSK5zo1VANEpDBoHhfM1l6mme5jOQrR/iPijLKGQNAKqIcaY0No+Hpeae8t9uHfeyiuuOrFHKHD4U/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qJXJTsAErt5uTyu9+Wh7VtG6eDsOvT5PwfyrDdrfj2/GCEs8JVzpGKZs8J4XJcIQeWqE6Jf8g/IguvyQODBCUgA7088+yex9RosuMZ4I+X6HpnkbP6sqLCBS0vmZNFj0GKthtWAc7ILQApq5bpo9wbousykonSjmx6CCKa2W17qwCQKBL2OuCxhq5tlh+EiQPbpAe6X5O2Gz8bUZl9m85hs52Maq4gqepVle X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9c6d9c14-6bba-4e28-5d86-08dbb83e1036 X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB2743.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 11:54:50.3746 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Xyr4U2Otah3fjMO0zXnA/pnjdqjuA4zOO/Sshj85hAwDcUYCcgSFPgv+HtOXdvPisOwsz7tzoyCeOnh0bfFHXg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB9346 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 18 Sep 2023 04:56:58 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777396665231675379 X-GMAIL-MSGID: 1777396665231675379 From: Christophe JAILLET In order to simplify some error handling paths and avoid code duplication, introduce thunderstrike_destroy() which undoes thunderstrike_create(). Signed-off-by: Christophe JAILLET Reviewed-by: Rahul Rameshbabu --- Notes: Changes: v1->v2: - Re-order operations in thunderstrike_destroy to be in LIFO order with regards to the operations in thunderstrike_create. v2->v3: - Refactor thunderstrike_destroy to take a thunderstrike instance pointer as a parameter and prevent a variable from being unused in shield_probe. drivers/hid/hid-nvidia-shield.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/hid/hid-nvidia-shield.c b/drivers/hid/hid-nvidia-shield.c index a566f9cdc97d..bc47e19ef117 100644 --- a/drivers/hid/hid-nvidia-shield.c +++ b/drivers/hid/hid-nvidia-shield.c @@ -915,6 +915,15 @@ static struct shield_device *thunderstrike_create(struct hid_device *hdev) return ERR_PTR(ret); } +static void thunderstrike_destroy(struct thunderstrike *ts) +{ + led_classdev_unregister(&ts->led_dev); + power_supply_unregister(ts->base.battery_dev.psy); + if (ts->haptics_dev) + input_unregister_device(ts->haptics_dev); + ida_free(&thunderstrike_ida, ts->id); +} + static int android_input_mapping(struct hid_device *hdev, struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, unsigned long **bit, @@ -1074,11 +1083,7 @@ static int shield_probe(struct hid_device *hdev, const struct hid_device_id *id) err_stop: hid_hw_stop(hdev); err_ts_create: - power_supply_unregister(ts->base.battery_dev.psy); - if (ts->haptics_dev) - input_unregister_device(ts->haptics_dev); - led_classdev_unregister(&ts->led_dev); - ida_free(&thunderstrike_ida, ts->id); + thunderstrike_destroy(ts); return ret; } @@ -1090,11 +1095,7 @@ static void shield_remove(struct hid_device *hdev) ts = container_of(dev, struct thunderstrike, base); hid_hw_close(hdev); - power_supply_unregister(dev->battery_dev.psy); - if (ts->haptics_dev) - input_unregister_device(ts->haptics_dev); - led_classdev_unregister(&ts->led_dev); - ida_free(&thunderstrike_ida, ts->id); + thunderstrike_destroy(ts); del_timer_sync(&ts->psy_stats_timer); cancel_work_sync(&ts->hostcmd_req_work); hid_hw_stop(hdev);