From patchwork Thu Jun 14 14:30:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanno Zulla X-Patchwork-Id: 10464447 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 AEBCB601F9 for ; Thu, 14 Jun 2018 14:31:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 923A528B40 for ; Thu, 14 Jun 2018 14:31:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8FDFA28C1A; Thu, 14 Jun 2018 14:31: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=-7.9 required=2.0 tests=BAYES_00, 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 71CE728B40 for ; Thu, 14 Jun 2018 14:30:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965720AbeFNOav (ORCPT ); Thu, 14 Jun 2018 10:30:51 -0400 Received: from zoot.epublica.de ([78.46.103.157]:59462 "EHLO zoot.epublica.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965815AbeFNOat (ORCPT ); Thu, 14 Jun 2018 10:30:49 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by zoot.epublica.de (Postfix) with ESMTP id A27A41840A78; Thu, 14 Jun 2018 16:30:47 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zoot.epublica.de Received: from zoot.epublica.de ([127.0.0.1]) by localhost (zoot.epublica.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YUEP0TzW3Axp; Thu, 14 Jun 2018 16:30:47 +0200 (CEST) Received: from [10.1.0.41] (ip1f12a024.dynamic.kabel-deutschland.de [31.18.160.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by zoot.epublica.de (Postfix) with ESMTPSA id 167891840A44; Thu, 14 Jun 2018 16:30:47 +0200 (CEST) Subject: [PATCH 3/5] HID: hid-sony.c: Use devm_ api to simplify sony_leds_init() From: Hanno Zulla Cc: Jiri Kosina , Benjamin Tissoires , linux-input References: <76bacb70-f61e-6b00-233b-92c43aff1fca@hanno.de> <27d9fd86-258d-261f-60c6-80020131a617@hanno.de> Message-ID: Date: Thu, 14 Jun 2018 16:30:46 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Language: de-LU To: unlisted-recipients:; (no To-header on input) 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 [PATCH 3/5] HID: hid-sony.c: Use devm_ api to simplify sony_leds_init() Using devm_ calls, the resources of the Sony game devices's features are tied to the main device handle, making it easier to handle errors and teardown inside the device driver. Altogether, this reduces complexity of the driver source. Signed-off-by: Hanno Zulla --- drivers/hid/hid-sony.c | 42 +++++------------------------------------- 1 file changed, 5 insertions(+), 37 deletions(-) diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index ebad1381e177..7c1c56d13122 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -1940,25 +1940,6 @@ static int sony_led_blink_set(struct led_classdev *led, unsigned long *delay_on, return 0; } -static void sony_leds_remove(struct sony_sc *sc) -{ - struct led_classdev *led; - int n; - - BUG_ON(!(sc->quirks & SONY_LED_SUPPORT)); - - for (n = 0; n < sc->led_count; n++) { - led = sc->leds[n]; - sc->leds[n] = NULL; - if (!led) - continue; - led_classdev_unregister(led); - kfree(led); - } - - sc->led_count = 0; -} - static int sony_leds_init(struct sony_sc *sc) { struct hid_device *hdev = sc->hdev; @@ -2031,11 +2012,10 @@ static int sony_leds_init(struct sony_sc *sc) if (use_ds4_names) name_sz = strlen(dev_name(&hdev->dev)) + strlen(ds4_name_str[n]) + 2; - led = kzalloc(sizeof(struct led_classdev) + name_sz, GFP_KERNEL); + led = devm_kzalloc(&hdev->dev, sizeof(struct led_classdev) + name_sz, GFP_KERNEL); if (!led) { hid_err(hdev, "Couldn't allocate memory for LED %d\n", n); - ret = -ENOMEM; - goto error_leds; + return -ENOMEM; } name = (void *)(&led[1]); @@ -2056,21 +2036,14 @@ static int sony_leds_init(struct sony_sc *sc) sc->leds[n] = led; - ret = led_classdev_register(&hdev->dev, led); + ret = devm_led_classdev_register(&hdev->dev, led); if (ret) { hid_err(hdev, "Failed to register LED %d\n", n); - sc->leds[n] = NULL; - kfree(led); - goto error_leds; + return ret; } } - return ret; - -error_leds: - sony_leds_remove(sc); - - return ret; + return 0; } static void sixaxis_send_output_report(struct sony_sc *sc) @@ -2832,8 +2805,6 @@ static int sony_input_configured(struct hid_device *hdev, device_remove_file(&sc->hdev->dev, &dev_attr_firmware_version); if (sc->hw_version) device_remove_file(&sc->hdev->dev, &dev_attr_hardware_version); - if (sc->quirks & SONY_LED_SUPPORT) - sony_leds_remove(sc); if (sc->quirks & SONY_BATTERY_SUPPORT) sony_battery_remove(sc); sony_cancel_work_sync(sc); @@ -2914,9 +2885,6 @@ static void sony_remove(struct hid_device *hdev) hid_hw_close(hdev); - if (sc->quirks & SONY_LED_SUPPORT) - sony_leds_remove(sc); - if (sc->quirks & SONY_BATTERY_SUPPORT) sony_battery_remove(sc);