From patchwork Fri May 19 07:44:44 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: 9736111 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 207AC6041F for ; Fri, 19 May 2017 07:45:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BE6F288D2 for ; Fri, 19 May 2017 07:45:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 10BE3288EE; Fri, 19 May 2017 07:45:08 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 B3854288E7 for ; Fri, 19 May 2017 07:45:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751970AbdESHpC (ORCPT ); Fri, 19 May 2017 03:45:02 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:35698 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751738AbdESHo7 (ORCPT ); Fri, 19 May 2017 03:44:59 -0400 Received: by mail-wm0-f67.google.com with SMTP id v4so16458475wmb.2 for ; Fri, 19 May 2017 00:44:59 -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=txNfPpw7U0RYVHYEH7Daki5VDp05EdlTQAFYgo3tDBY=; b=ThGNQURrfv9LhdZJYWa08tTlcyBS8Qne0LmZEukkdioLLRsNo0bbkS8xSsWGwGqR99 nSffULsZzJV4VSHBbvE9zMir3/xE11ZSdARjrDhMav5Zr3FyAz3YYYGX7vIXbOaNdVJn xGS4Hn6QsmRQuIyKe9dG4ApSoyaZ+tfg5GcHI= 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=txNfPpw7U0RYVHYEH7Daki5VDp05EdlTQAFYgo3tDBY=; b=g8+EW1BAjPWbvf7TWIOickrkeZy84JFeI/3hGtYoM1SkzNmnxrpQ/JHaJVLW1gZg1W riAPoiIBI0oDNRMfEbYreqYq++yQb2CYOHY4yDWzvZrIFjVFD84vyzuFek429pDOl8aD PWtDhvDkQkBJdJ4uNZEiF4+B6n3QT2Zrr4IdAnH3jH4DsshGLeMrdt16f8qvweOmmVHe 0xxJdCvJdvg8AHZwx3XlVlqEKayunyqiq8XrvOqRhSPnHxpLvf1I5/QjHDVqqrOygWMM 61tPK7zri6VTVbVyXEc3qAVMDn1kiyKe4phI/zEc1GVsSVF0lOAhDcehLOS9TxClVkxq mqHQ== X-Gm-Message-State: AODbwcAD5dwrfeg9z3HXm2TzY5lmQRa4v9TduJi7lC6Jl7jBa2J62vcq +Hnzss6Lg1DasaST X-Received: by 10.25.23.29 with SMTP id n29mr1992727lfi.101.1495179898302; Fri, 19 May 2017 00:44:58 -0700 (PDT) Received: from ozzy.nask.waw.pl ([2001:a10:160:3::3]) by smtp.googlemail.com with ESMTPSA id a1sm811623lfb.15.2017.05.19.00.44.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 May 2017 00:44:57 -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 v2 4/8] platform/x86: fujitsu-laptop: allocate struct fujitsu_laptop in acpi_fujitsu_laptop_add() Date: Fri, 19 May 2017 09:44:44 +0200 Message-Id: <20170519074448.12716-5-kernel@kempniu.pl> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170519074448.12716-1-kernel@kempniu.pl> References: <20170519074448.12716-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 Only allocate memory for struct fujitsu_laptop when the FUJ02E3 ACPI device is present. Use devm_kzalloc() for allocating memory to simplify cleanup. Signed-off-by: Michał Kępień --- drivers/platform/x86/fujitsu-laptop.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c index 1124070aad2d..3916f0ae59f3 100644 --- a/drivers/platform/x86/fujitsu-laptop.c +++ b/drivers/platform/x86/fujitsu-laptop.c @@ -776,6 +776,7 @@ static int acpi_fujitsu_laptop_leds_register(struct acpi_device *device) static int acpi_fujitsu_laptop_add(struct acpi_device *device) { + struct fujitsu_laptop *priv; int state = 0; int error; int i; @@ -783,11 +784,16 @@ static int acpi_fujitsu_laptop_add(struct acpi_device *device) if (!device) return -EINVAL; + priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + fujitsu_laptop = priv; fujitsu_laptop->acpi_handle = device->handle; sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_LAPTOP_DEVICE_NAME); sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS); - device->driver_data = fujitsu_laptop; + device->driver_data = priv; /* kfifo */ spin_lock_init(&fujitsu_laptop->fifo_lock); @@ -1014,22 +1020,14 @@ static int __init fujitsu_init(void) /* Register laptop driver */ - fujitsu_laptop = kzalloc(sizeof(struct fujitsu_laptop), GFP_KERNEL); - if (!fujitsu_laptop) { - ret = -ENOMEM; - goto err_unregister_platform_driver; - } - ret = acpi_bus_register_driver(&acpi_fujitsu_laptop_driver); if (ret) - goto err_free_fujitsu_laptop; + goto err_unregister_platform_driver; pr_info("driver " FUJITSU_DRIVER_VERSION " successfully loaded\n"); return 0; -err_free_fujitsu_laptop: - kfree(fujitsu_laptop); err_unregister_platform_driver: platform_driver_unregister(&fujitsu_pf_driver); err_unregister_acpi: @@ -1042,8 +1040,6 @@ static void __exit fujitsu_cleanup(void) { acpi_bus_unregister_driver(&acpi_fujitsu_laptop_driver); - kfree(fujitsu_laptop); - platform_driver_unregister(&fujitsu_pf_driver); acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);