From patchwork Tue Mar 14 10:26:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWljaGHFgiBLxJlwaWXFhA==?= X-Patchwork-Id: 9622963 X-Patchwork-Delegate: dvhart@infradead.org 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 2C67660492 for ; Tue, 14 Mar 2017 10:27:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10CB7283F3 for ; Tue, 14 Mar 2017 10:27:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0582428410; Tue, 14 Mar 2017 10:27:25 +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.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable 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 A77EB283F3 for ; Tue, 14 Mar 2017 10:27:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751188AbdCNK1N (ORCPT ); Tue, 14 Mar 2017 06:27:13 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:33832 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751014AbdCNK0n (ORCPT ); Tue, 14 Mar 2017 06:26:43 -0400 Received: by mail-lf0-f67.google.com with SMTP id y193so13745336lfd.1 for ; Tue, 14 Mar 2017 03:26:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kempniu.pl; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JbsPfTYZjxka9RWPoJjjrypl/mglb5SIOtYsVzPKL3M=; b=he7nlA2sJPKs5B+5JaNZcpStyL5ncyKaxyU+nuIAbyr8qvBDR2KrkYdfMGf4+Vrp17 eeF1E+b9EWN4bgQZHU42NvYFrCtu18ZjkmJMP/I4eFuN8oE7/2YAH1y32Mt5Ddr0uHtc RScc84UGmESTnM8dItxQ2paAhXTccNnLW3x5A= 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:mime-version:content-transfer-encoding; bh=JbsPfTYZjxka9RWPoJjjrypl/mglb5SIOtYsVzPKL3M=; b=oFiy+V98kRGb4Ami5DmvpQZCQXQmxQz+y+gO23tcRFMiS+cu89eK/v6W3yo/CtzfJ3 h1plYi2DUBDoEmBu9uCjhdc0fO3jNRR488we7rnaCFBY5tymMJT6a3LSvWyoC1C85+/Y qIo0G6HuHeqkNwqIoeWiyHjGFdleKjn0NxTHMsAkH8wOBg4PUUgiqEBPEiIyiK4qHV/v PmPD/P/wetnwpITM4KK6QOAYWrS2Rbsq6a0LbUpz6dH7jIFjTCutxDIuy0iCo9X7/uKn Kio9AHqgkSb0rLOWpAOuxzmoPVkPfEo5CREIF+yKH+Tr6phQlN/qws0n3yoArDI7ClfA wNsg== X-Gm-Message-State: AMke39lCCotojIPUn+wbyZFKfdfbXH8thBMYtyj8wGeV7EL9hQ6tcL6+eNORFuf7VUuqnw== X-Received: by 10.25.221.66 with SMTP id u63mr9666454lfg.52.1489487200841; Tue, 14 Mar 2017 03:26:40 -0700 (PDT) Received: from ozzy.hq.kempniu.pl ([2001:a10:160:3::3]) by smtp.googlemail.com with ESMTPSA id h62sm4186154lfh.62.2017.03.14.03.26.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Mar 2017 03:26:40 -0700 (PDT) From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= To: Jonathan Woithe , Darren Hart , Andy Shevchenko Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] platform/x86: fujitsu-laptop: add and remove platform device in separate functions Date: Tue, 14 Mar 2017 11:26:29 +0100 Message-Id: <20170314102631.8203-4-kernel@kempniu.pl> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170314102631.8203-1-kernel@kempniu.pl> References: <20170314102631.8203-1-kernel@kempniu.pl> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Platform device handling adds a lot of complexity to fujitsu_init(), which hinders its readability. Extract code responsible for adding and removing the platform device to separate functions. Adjust whitespace to make checkpatch happy. Signed-off-by: Michał Kępień --- drivers/platform/x86/fujitsu-laptop.c | 66 +++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c index 9719c821d64f..421402a19bb9 100644 --- a/drivers/platform/x86/fujitsu-laptop.c +++ b/drivers/platform/x86/fujitsu-laptop.c @@ -765,6 +765,40 @@ static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event) /* ACPI device for hotkey handling */ +static int fujitsu_laptop_platform_add(void) +{ + int ret; + + fujitsu_bl->pf_device = platform_device_alloc("fujitsu-laptop", -1); + if (!fujitsu_bl->pf_device) + return -ENOMEM; + + ret = platform_device_add(fujitsu_bl->pf_device); + if (ret) + goto err_put_platform_device; + + ret = sysfs_create_group(&fujitsu_bl->pf_device->dev.kobj, + &fujitsu_pf_attribute_group); + if (ret) + goto err_del_platform_device; + + return 0; + +err_del_platform_device: + platform_device_del(fujitsu_bl->pf_device); +err_put_platform_device: + platform_device_put(fujitsu_bl->pf_device); + + return ret; +} + +static void fujitsu_laptop_platform_remove(void) +{ + sysfs_remove_group(&fujitsu_bl->pf_device->dev.kobj, + &fujitsu_pf_attribute_group); + platform_device_unregister(fujitsu_bl->pf_device); +} + static int acpi_fujitsu_laptop_add(struct acpi_device *device) { int result = 0; @@ -1146,25 +1180,13 @@ static int __init fujitsu_init(void) /* Register platform stuff */ - fujitsu_bl->pf_device = platform_device_alloc("fujitsu-laptop", -1); - if (!fujitsu_bl->pf_device) { - ret = -ENOMEM; - goto err_unregister_acpi; - } - - ret = platform_device_add(fujitsu_bl->pf_device); - if (ret) - goto err_put_platform_device; - - ret = - sysfs_create_group(&fujitsu_bl->pf_device->dev.kobj, - &fujitsu_pf_attribute_group); + ret = fujitsu_laptop_platform_add(); if (ret) - goto err_del_platform_device; + goto err_unregister_acpi; ret = platform_driver_register(&fujitsu_pf_driver); if (ret) - goto err_remove_sysfs_group; + goto err_remove_platform_device; /* Register laptop driver */ @@ -1186,13 +1208,8 @@ static int __init fujitsu_init(void) kfree(fujitsu_laptop); err_unregister_platform_driver: platform_driver_unregister(&fujitsu_pf_driver); -err_remove_sysfs_group: - sysfs_remove_group(&fujitsu_bl->pf_device->dev.kobj, - &fujitsu_pf_attribute_group); -err_del_platform_device: - platform_device_del(fujitsu_bl->pf_device); -err_put_platform_device: - platform_device_put(fujitsu_bl->pf_device); +err_remove_platform_device: + fujitsu_laptop_platform_remove(); err_unregister_acpi: acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver); err_free_fujitsu_bl: @@ -1209,10 +1226,7 @@ static void __exit fujitsu_cleanup(void) platform_driver_unregister(&fujitsu_pf_driver); - sysfs_remove_group(&fujitsu_bl->pf_device->dev.kobj, - &fujitsu_pf_attribute_group); - - platform_device_unregister(fujitsu_bl->pf_device); + fujitsu_laptop_platform_remove(); acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);