From patchwork Fri May 19 07:44:42 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: 9736109 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 C4CEE6034C for ; Fri, 19 May 2017 07:45:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BFCFF2881B for ; Fri, 19 May 2017 07:45:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B26D3288E6; Fri, 19 May 2017 07:45:07 +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 57B9D2881B for ; Fri, 19 May 2017 07:45:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751772AbdESHpA (ORCPT ); Fri, 19 May 2017 03:45:00 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:36511 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751073AbdESHo5 (ORCPT ); Fri, 19 May 2017 03:44:57 -0400 Received: by mail-wm0-f67.google.com with SMTP id k15so15132463wmh.3 for ; Fri, 19 May 2017 00:44:57 -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=vMLJv2DlcwwqCl8dDEgvJhT8158tmAyQOSHAdXQJkt8=; b=YQlZKP2NTXmB14huUH5a7hmpxywz1qYHKZJUx5oLs94EeH2aFo3m7I5WcQfAbPkcQO QoJ1W5p1YMhMRcLWvm5BaVPP0/q6pUppBT0Ejpo3GqzT8ve27lSnZ9tJ5LmJfxs4xtVw 6Hpdh8SWKYI8W+l5ABTrTZKs8zSvV6YWnTW9Y= 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=vMLJv2DlcwwqCl8dDEgvJhT8158tmAyQOSHAdXQJkt8=; b=MrzgllTXLf7nyf48SNM6T4pAA12s0ei89WuOAI8RSoz3zIOQ+wO2CtbdvcaCJfB3k3 w39SU6byT9bt80F9ybJxI11etv/7ueRhHHtrwYBIXzrDt+KHwS8Aq3rzzoLqWb/iWVkr XX1IzSMIL77f78FHdpfJq3D9TQ0iua2JHVvm9n4wIyILiLFhB9idC0qmRapT+Q8Hc+Ns zhu4BXBhHyMmOHjRz9Yp1Sym0oJHFG97OtSX62ybk7vqdFBkKSx5uOKYqtRHiCp/Ys8k gsLq9vbuUjhUNZeQ3xxD3LDphselAMfk/13SqS5kG5XyvZWW6jtZKS100NpKptmESpMk YbUA== X-Gm-Message-State: AODbwcCNPEiooeQKjteHX8sRVpcrmN0qk78iQQtIo1s/KkjDgBD/5wRB er+wHT9812111AJU X-Received: by 10.25.16.232 with SMTP id 101mr1736027lfq.54.1495179896397; Fri, 19 May 2017 00:44:56 -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.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 May 2017 00:44:55 -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 2/8] platform/x86: fujitsu-laptop: allocate struct fujitsu_bl in acpi_fujitsu_bl_add() Date: Fri, 19 May 2017 09:44:42 +0200 Message-Id: <20170519074448.12716-3-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_bl when the FUJ02B1 ACPI device is present. Use devm_kzalloc() for allocating memory to simplify cleanup. Due to the fact that the power property of the backlight device created by the backlight driver is accessed from acpi_fujitsu_laptop_add(), pointer to the allocated memory will remain stored in a module-wide variable until the backlight driver is extracted into a separate module. Signed-off-by: Michał Kępień --- drivers/platform/x86/fujitsu-laptop.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c index 024ef339179a..63a9b98967fa 100644 --- a/drivers/platform/x86/fujitsu-laptop.c +++ b/drivers/platform/x86/fujitsu-laptop.c @@ -392,6 +392,7 @@ static int fujitsu_backlight_register(struct acpi_device *device) static int acpi_fujitsu_bl_add(struct acpi_device *device) { + struct fujitsu_bl *priv; int state = 0; int error; @@ -401,10 +402,15 @@ static int acpi_fujitsu_bl_add(struct acpi_device *device) if (!device) return -EINVAL; + priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + fujitsu_bl = priv; fujitsu_bl->acpi_handle = device->handle; sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_BL_DEVICE_NAME); sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS); - device->driver_data = fujitsu_bl; + device->driver_data = priv; error = acpi_fujitsu_bl_input_setup(device); if (error) @@ -837,7 +843,7 @@ static int acpi_fujitsu_laptop_add(struct acpi_device *device) pr_info("BTNI: [0x%x]\n", call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0)); /* Sync backlight power status */ - if (fujitsu_bl->bl_device && + if (fujitsu_bl && fujitsu_bl->bl_device && acpi_video_get_backlight_type() == acpi_backlight_vendor) { if (call_fext_func(FUNC_BACKLIGHT, 0x2, 0x4, 0x0) == 3) fujitsu_bl->bl_device->props.power = FB_BLANK_POWERDOWN; @@ -995,13 +1001,9 @@ static int __init fujitsu_init(void) if (acpi_disabled) return -ENODEV; - fujitsu_bl = kzalloc(sizeof(struct fujitsu_bl), GFP_KERNEL); - if (!fujitsu_bl) - return -ENOMEM; - ret = acpi_bus_register_driver(&acpi_fujitsu_bl_driver); if (ret) - goto err_free_fujitsu_bl; + return ret; /* Register platform stuff */ @@ -1031,8 +1033,6 @@ static int __init fujitsu_init(void) platform_driver_unregister(&fujitsu_pf_driver); err_unregister_acpi: acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver); -err_free_fujitsu_bl: - kfree(fujitsu_bl); return ret; } @@ -1047,8 +1047,6 @@ static void __exit fujitsu_cleanup(void) acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver); - kfree(fujitsu_bl); - pr_info("driver unloaded\n"); }