From patchwork Wed Mar 24 12:55:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12161037 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5EEEC433E3 for ; Wed, 24 Mar 2021 12:57:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 96B6961A0F for ; Wed, 24 Mar 2021 12:57:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234497AbhCXM4a (ORCPT ); Wed, 24 Mar 2021 08:56:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234506AbhCXM4D (ORCPT ); Wed, 24 Mar 2021 08:56:03 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC773C0613DE for ; Wed, 24 Mar 2021 05:56:02 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id hq27so32679891ejc.9 for ; Wed, 24 Mar 2021 05:56:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Yt30BylsVFl1b+dQoUipKgO72wces4+1J22+XTIwK04=; b=V8+VKpPq1U3Ka+KRlgK1LrfG0FXSzQm1cNKLBQ6O2nxnxVzkanqDoJuBIVMpFNTI/k CrUDsK6kgCZsvJCSO2qZhIbVvYynh64zRpkGOd7XjRj9bBMa/BU+XPghLVESFNnrkMx8 LXRT30o//+Lcnlh2q460VIEFZGMIRTWCBREme/3lfnKXtdLTXFklnjXHaitlMqwdUkk9 bMDPrzfjaoI141OP2Yd9QDjb9erYtStOxFtOhWuZL1+xgDfJFWDpF0kP3SRcjPS1UD8L fPxR2E4mQqREpdJsiSII//4O14+f7YIWtLv6bAihhtHKKt65mDTw988HWetaPFF9BYBJ u0aw== 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=Yt30BylsVFl1b+dQoUipKgO72wces4+1J22+XTIwK04=; b=TRLHiwgfwyFyG0P6jU756tb5kcFv2DCJAP7aJjqG5j52Ue7Zh3fw8LJ3VZ14+AxH7P G9TLgfxvAIoHIj+V0S+PHEDoukvkcN9MYEipKBDIr2gYd1oab31f1UPlNYNnYI3FstyV Ku94od5hnnD9GdTB4r9E1EFqywFUKcJaD4dT3yIcQP2TULjtYq5E1QQqVIK/F+0wRpd0 ysg9m0p86j4N7Ocb0Ylk+ff6Q1rCX+0saeZFQppc2OLjETeYm0nmzCmLTnsc1Y3WGUI2 wfkMXOBA7gtbjZ+pAKARjN5S+jW2wBALDwbKHWWOGgemQNlORpUqHNAeFfVBhQYaAWa4 6jsw== X-Gm-Message-State: AOAM532bzK8g6wLGVOa1fMNl71hCi6OcSClGt2qtGT7ih+iYRZa+J96z VFvo+b1gcLk8JJj2DDa7ZBVA7Q== X-Google-Smtp-Source: ABdhPJxreCAgoVxptS2To6BlyigUOXCdyHhdVvCZ3X35rkt7s2d0JLzqBu7v5QsTP1W7Eu45RVnMEQ== X-Received: by 2002:a17:906:b316:: with SMTP id n22mr3404360ejz.249.1616590561345; Wed, 24 Mar 2021 05:56:01 -0700 (PDT) Received: from localhost.localdomain ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id fi11sm880282ejb.73.2021.03.24.05.56.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 05:56:01 -0700 (PDT) From: Alexandru Ardelean To: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org Cc: coproscefalo@gmail.com, hdegoede@redhat.com, mgross@linux.intel.com, jic23@kernel.org, linux@deviqon.com, Alexandru Ardelean Subject: [PATCH 01/10] platform/x86: toshiba_acpi: bind life-time of toshiba_acpi_dev to parent Date: Wed, 24 Mar 2021 14:55:39 +0200 Message-Id: <20210324125548.45983-2-aardelean@deviqon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324125548.45983-1-aardelean@deviqon.com> References: <20210324125548.45983-1-aardelean@deviqon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org The 'toshiba_acpi_dev' object is allocated first and free'd last. We can bind it's life-time to the parent ACPI device object. This is a first step in using more device-managed allocated functions for this. The main intent is to try to convert the IIO framework to export only device-managed functions (i.e. devm_iio_device_alloc() and devm_iio_device_register()). It's still not 100% sure that this is possible, but for now, this is the process of taking it slowly in that direction. Signed-off-by: Alexandru Ardelean --- drivers/platform/x86/toshiba_acpi.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index fa7232ad8c39..6d298810b7bf 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -2998,8 +2998,6 @@ static int toshiba_acpi_remove(struct acpi_device *acpi_dev) if (toshiba_acpi) toshiba_acpi = NULL; - kfree(dev); - return 0; } @@ -3016,6 +3014,7 @@ static const char *find_hci_method(acpi_handle handle) static int toshiba_acpi_add(struct acpi_device *acpi_dev) { + struct device *parent = &acpi_dev->dev; struct toshiba_acpi_dev *dev; const char *hci_method; u32 dummy; @@ -3033,7 +3032,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev) return -ENODEV; } - dev = kzalloc(sizeof(*dev), GFP_KERNEL); + dev = devm_kzalloc(parent, sizeof(*dev), GFP_KERNEL); if (!dev) return -ENOMEM; dev->acpi_dev = acpi_dev; @@ -3045,7 +3044,6 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev) ret = misc_register(&dev->miscdev); if (ret) { pr_err("Failed to register miscdevice\n"); - kfree(dev); return ret; } From patchwork Wed Mar 24 12:55:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12161039 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA4B2C433E5 for ; Wed, 24 Mar 2021 12:57:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D066461A0D for ; Wed, 24 Mar 2021 12:57:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234708AbhCXM4b (ORCPT ); Wed, 24 Mar 2021 08:56:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234513AbhCXM4E (ORCPT ); Wed, 24 Mar 2021 08:56:04 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92663C0613DE for ; Wed, 24 Mar 2021 05:56:03 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id x21so27501646eds.4 for ; Wed, 24 Mar 2021 05:56:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vjfeStBI2DcHZmjQrx+N+dsAxgF1a/tnl6rrv3SVE6Q=; b=tekIiAZWW3kwi3DlNvLmMjX9jCWj63bcKAuPkI/Q5kJI1jxRdebmh1n9A/tlN0QDix AhF96gOTxQDa/INulpZewfZFCBHRT32NBq4aN7Wt9iCdCk3hqwXQu0HoXJcnqap2l8rT hp892/IN6CoTYtv4sXGNN0pSbemNt7+zWkpKgHHWadomhZp399P88VkrOkkjNOLK/EO1 7/wbr3XDjeBjDtw3cLPZB8UFskNHxNGG40xlP5icGyEQXICCz1O9EsMJb3DXQOXP3TOD Ci3Pr1aUf75aTPI9Grsc2yKD1Y1687FHnbcYBoFJve456VIQJ2f1B4xhuPoI55jOS2ev k91Q== 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=vjfeStBI2DcHZmjQrx+N+dsAxgF1a/tnl6rrv3SVE6Q=; b=Hav1ElwF9dr2Ss42i1EeSf/zEiR8BVlaawno8n0XG/GU98EZ2AUmpc4Mu3JNgn084G pvgCouCwEFDCCtGDaXsbpg88bmmZhNkpnsrmABWA0JLH9eDUE2izpe7GOnS9id/4XJbn WG1DEuYJh5QUEVbl32Bd2WSTMSy0nVfAGKapsNh16jF8vbw9AbsBwh19t3TQb1ikLL+O Wyz6e+L57SgpI4aMHh4TE0J0XlfavRPGXhHIqhm4Ke5Fc6k8kND2QgFGOeiOUhnOkdoS Rmi1OIXcjAjUh3LgwJ8oglNlkRo3oDn7sfYeg+J8T1H6plCHjPfB6ATiTWTSrsvOFun8 nbKw== X-Gm-Message-State: AOAM532ZkOPxdPcgF9fT44KXvPkfFydyLnarzQceCIOt+5wQIhKRO2ff idJmczFOOYIvu3jmiBWoXof55A== X-Google-Smtp-Source: ABdhPJyE/+A23QNDkwguoiMrfXl+jMVy6xCycwVkij0rRzaeQOah7cxBFhnpOcFlsG90OWCUZmfHRg== X-Received: by 2002:a05:6402:2076:: with SMTP id bd22mr3260352edb.378.1616590562364; Wed, 24 Mar 2021 05:56:02 -0700 (PDT) Received: from localhost.localdomain ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id fi11sm880282ejb.73.2021.03.24.05.56.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 05:56:02 -0700 (PDT) From: Alexandru Ardelean To: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org Cc: coproscefalo@gmail.com, hdegoede@redhat.com, mgross@linux.intel.com, jic23@kernel.org, linux@deviqon.com, Alexandru Ardelean Subject: [PATCH 02/10] platform/x86: toshiba_acpi: use devm_add_action_or_reset() for singleton clear Date: Wed, 24 Mar 2021 14:55:40 +0200 Message-Id: <20210324125548.45983-3-aardelean@deviqon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324125548.45983-1-aardelean@deviqon.com> References: <20210324125548.45983-1-aardelean@deviqon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org The only reason to do this is to enforce the ordering of deinitialization, when the conversion of the device-managed functions is done. The singleton object should be cleared right before it is free'd. Signed-off-by: Alexandru Ardelean --- drivers/platform/x86/toshiba_acpi.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index 6d298810b7bf..c5284601bc2a 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -2995,9 +2995,6 @@ static int toshiba_acpi_remove(struct acpi_device *acpi_dev) rfkill_destroy(dev->wwan_rfk); } - if (toshiba_acpi) - toshiba_acpi = NULL; - return 0; } @@ -3012,6 +3009,11 @@ static const char *find_hci_method(acpi_handle handle) return NULL; } +static void toshiba_acpi_singleton_clear(void *data) +{ + toshiba_acpi = NULL; +} + static int toshiba_acpi_add(struct acpi_device *acpi_dev) { struct device *parent = &acpi_dev->dev; @@ -3035,6 +3037,13 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev) dev = devm_kzalloc(parent, sizeof(*dev), GFP_KERNEL); if (!dev) return -ENOMEM; + + ret = devm_add_action_or_reset(parent, + toshiba_acpi_singleton_clear, + NULL); + if (ret) + return ret; + dev->acpi_dev = acpi_dev; dev->method_hci = hci_method; dev->miscdev.minor = MISC_DYNAMIC_MINOR; From patchwork Wed Mar 24 12:55:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12161041 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BC77C433E8 for ; Wed, 24 Mar 2021 12:57:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0501661A2D for ; Wed, 24 Mar 2021 12:57:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234521AbhCXM4f (ORCPT ); Wed, 24 Mar 2021 08:56:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234526AbhCXM4F (ORCPT ); Wed, 24 Mar 2021 08:56:05 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FCDCC0613E1 for ; Wed, 24 Mar 2021 05:56:04 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id l4so32672490ejc.10 for ; Wed, 24 Mar 2021 05:56:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=frWPEUlqs06JkDdBYmeAt9wV6HnzyvV5zsDKfCcKu+M=; b=GmpYQYHQItWYbKynRGeuKnH14x7wgEAUOeru1GAukTiYyBVZyNuC62e9vPztxuB3b+ o9qG1cfC4xJt5eKWXvGYooq4t61JA5rELbrYnZC5EImztn7SNINNZaLjhtNqYTZPU1lG 7HDtCpP+MNoS8NfsghQJc1E42HJqvPOPjK1ajPTu6/XtqpQfNdX/CeS3ANPpsNm/o9ED xDwA7eSuWn46kA6P5NmMwaateIOfXhnoptqZyvF9gYKJhhCg+kP0Prb/bLGnSsfNc52a i/ddBMFrew2LvfV46CLC6Wa9q+r3n1hZeM5EfvzjgzxZzvQ0xEdou4zZQsUFhFSTfULD oSFw== 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=frWPEUlqs06JkDdBYmeAt9wV6HnzyvV5zsDKfCcKu+M=; b=fy+53mZA3dtw1ATk18/Ak9IkqOlYntumDstp8lneXLiMn3JvwYr43k3ld4M5V0uXRi TBl3cZAvYXraz/yx67L+Kqqea2Qfpztfr+53VshCTh2TH07Spm5Atr9DXFV91Z290haj KCISLTKx/Gkyh3IqlrzzhcRDhhJCgaUNANIucI6iHB8rAm8QFcm8U96R++/WWji2BUfk +FKNFwf/R41zimL3JsFhePx0DlxX/Wrxf3AWvgwtj0tNJKmyCTQeLn2oRndgsfu8fMfi K8ZJJRo/k1WugxZwFHHCn80kdM8uaQ18ThqZgZHEkCX1E7rGv2VCwlCqA7Y9Aar9djdk jgcg== X-Gm-Message-State: AOAM532ZFCC0YjQRAsSCColS2gNIreryR9q0iEyR4sqB1dhCGiGCPLmy 9SazmoCheiMbEzq80lmQmzCeRg== X-Google-Smtp-Source: ABdhPJzpxStqf4689RHXTCYW0kDpZhBA8gf9Qrkx0RVSK+qnEqvmhL4BwM1bxJkrz6O7EHd8bIM0+g== X-Received: by 2002:a17:907:a042:: with SMTP id gz2mr3506188ejc.174.1616590563362; Wed, 24 Mar 2021 05:56:03 -0700 (PDT) Received: from localhost.localdomain ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id fi11sm880282ejb.73.2021.03.24.05.56.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 05:56:03 -0700 (PDT) From: Alexandru Ardelean To: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org Cc: coproscefalo@gmail.com, hdegoede@redhat.com, mgross@linux.intel.com, jic23@kernel.org, linux@deviqon.com, Alexandru Ardelean Subject: [PATCH 03/10] platform/x86: toshiba_acpi: bind registration of miscdev object to parent Date: Wed, 24 Mar 2021 14:55:41 +0200 Message-Id: <20210324125548.45983-4-aardelean@deviqon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324125548.45983-1-aardelean@deviqon.com> References: <20210324125548.45983-1-aardelean@deviqon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This change moves the registration of the Toshiba ACPI miscdev to be handled by the devm_add_action_or_reset() hook. This way, the miscdev will be unregistered when the reference count of the parent device object goes to zero. This also changes the order of cleanup in toshiba_acpi_remove(), where the miscdev was deregistered first. Now it will be deregistered right before the toshiba_acpi_dev object is free'd. Signed-off-by: Alexandru Ardelean Acked-by: Jonathan Cameron --- drivers/platform/x86/toshiba_acpi.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index c5284601bc2a..53ef565378ef 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -2963,8 +2963,6 @@ static int toshiba_acpi_remove(struct acpi_device *acpi_dev) { struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev); - misc_deregister(&dev->miscdev); - remove_toshiba_proc_entries(dev); if (dev->accelerometer_supported && dev->indio_dev) { @@ -3014,6 +3012,13 @@ static void toshiba_acpi_singleton_clear(void *data) toshiba_acpi = NULL; } +static void toshiba_acpi_misc_deregister(void *data) +{ + struct miscdevice *miscdev = data; + + misc_deregister(miscdev); +} + static int toshiba_acpi_add(struct acpi_device *acpi_dev) { struct device *parent = &acpi_dev->dev; @@ -3056,6 +3061,11 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev) return ret; } + ret = devm_add_action_or_reset(parent, toshiba_acpi_misc_deregister, + &dev->miscdev); + if (ret) + return ret; + acpi_dev->driver_data = dev; dev_set_drvdata(&acpi_dev->dev, dev); From patchwork Wed Mar 24 12:55:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12161043 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBE1DC433EC for ; Wed, 24 Mar 2021 12:57:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AA5DA61A10 for ; Wed, 24 Mar 2021 12:57:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234540AbhCXM4h (ORCPT ); Wed, 24 Mar 2021 08:56:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234546AbhCXM4G (ORCPT ); Wed, 24 Mar 2021 08:56:06 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94496C0613DE for ; Wed, 24 Mar 2021 05:56:05 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id k10so32711710ejg.0 for ; Wed, 24 Mar 2021 05:56:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UFsO3CjdzjvSKalFHfalsmH1Z1YFNl8tTKEel8RPQ5w=; b=TQDfwW+RWxoC195Fzua0pk1St/0sgu8PKZyJu7DVkyw9hXK8uBUvhbeugCJaGDeBa1 XOjgEjOI0P71D0gflcRsicksf5UFqjY0oDU6w6+pgeDt9g8NvAV2n4mJ3aX37y0QNCH/ 9LIPsAzWyRzNHSYMERj840gXWk7xrth+EsdW2C5+1VlyTkG4PE1IkJ5buDdwwCQn7TN9 rGAhoe9Q49HZCC7RFbF29ucVwlDeZPZkNbpsoJZcAon8HijLMGTxBvSuiVdXAPc67zXL UjSPLB5QbMbIsZrZoA+MPtjMoomX4ZhbJWwlaQiFyLYgqEghv7r3fto2tprog9M2aEHr CoQQ== 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=UFsO3CjdzjvSKalFHfalsmH1Z1YFNl8tTKEel8RPQ5w=; b=h1EGFGBI366LEQfPEZ4vxK6pu+Z5541TKEtTCsGPocdKriPOwn9dCDthoBezAfynKM 4psCQE7DFXce+Ohd3ZfFfTbgOmc03/VWGrJu9/ZBXNFLCcFv5qIn4Ry53ouiF8FWGhr7 wG0MuHQm7q0+S+TrZE9ZNQ2zyu6SHWXx677sY59llc2spZccegX+1qk9rE6uuLHlTVSR h5ZORExHyhqRHuUW9fZU+TpjvQZiperZsGiVBeEoAFHRTT4nmbmyEi74NWKMo3YC/E2f bA0foqyeYHfNE96GefiHAGTCdQ8S8wttgkfIYiHVL/A609V2wJcuSR5Uspf3MRsU8zpo FKlg== X-Gm-Message-State: AOAM530nHM/3ISQ9eSMXxbCR1n/zNPfH6SCwjokCdjNzYncy0+J6mCzW OCnPW94ZVZEx0C/Y5eiUl7L1EA== X-Google-Smtp-Source: ABdhPJwJyL58sUWBrXWfLdOooX4vIKkqXRt2tWpnGi0EvOn86rz78Pp4fgk7jt1d1LArIR2ZJgoeog== X-Received: by 2002:a17:906:7f84:: with SMTP id f4mr3435189ejr.525.1616590564364; Wed, 24 Mar 2021 05:56:04 -0700 (PDT) Received: from localhost.localdomain ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id fi11sm880282ejb.73.2021.03.24.05.56.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 05:56:04 -0700 (PDT) From: Alexandru Ardelean To: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org Cc: coproscefalo@gmail.com, hdegoede@redhat.com, mgross@linux.intel.com, jic23@kernel.org, linux@deviqon.com, Alexandru Ardelean Subject: [PATCH 04/10] platform/x86: toshiba_acpi: use device-managed functions for input device Date: Wed, 24 Mar 2021 14:55:42 +0200 Message-Id: <20210324125548.45983-5-aardelean@deviqon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324125548.45983-1-aardelean@deviqon.com> References: <20210324125548.45983-1-aardelean@deviqon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This change uses device managed functions to handle the deregistration of the keyboard resources when the refcount of the parent device goes to zero. For the input device devm_input_allocate_device() must be used, and after that it will be bound also for auto-deregistration when input_device_register() is called. The work object is registered for uninit with devm_add_action(), which will be called on device unregister only. The i8042 filter is registered with devm_add_action() as well, but it is done last in the toshiba_acpi_setup_keyboard() function. This is a little quirky, because this relies on the fact that there can a single toshiba_acpi_dev object. Signed-off-by: Alexandru Ardelean --- drivers/platform/x86/toshiba_acpi.c | 55 +++++++++++++++++++---------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index 53ef565378ef..556f2cc99bad 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -186,7 +186,6 @@ struct toshiba_acpi_dev { unsigned int video_supported:1; unsigned int fan_supported:1; unsigned int system_event_supported:1; - unsigned int ntfy_supported:1; unsigned int info_supported:1; unsigned int tr_backlight_supported:1; unsigned int kbd_illum_supported:1; @@ -2756,9 +2755,23 @@ static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev) } } -static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev) +static void toshiba_acpi_cancel_hotkey_work(void *data) +{ + struct work_struct *hotkey_work = data; + + cancel_work_sync(hotkey_work); +} + +static void toshiba_acpi_i8042_remove_filter(void *data) +{ + i8042_remove_filter(toshiba_acpi_i8042_filter); +} + +static int toshiba_acpi_setup_keyboard(struct device *parent, + struct toshiba_acpi_dev *dev) { const struct key_entry *keymap = toshiba_acpi_keymap; + bool ntfy_supported = false; acpi_handle ec_handle; int error; @@ -2779,7 +2792,7 @@ static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev) if (toshiba_hotkey_event_type_get(dev, &dev->hotkey_event_type)) pr_notice("Unable to query Hotkey Event Type\n"); - dev->hotkey_dev = input_allocate_device(); + dev->hotkey_dev = devm_input_allocate_device(parent); if (!dev->hotkey_dev) return -ENOMEM; @@ -2798,7 +2811,7 @@ static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev) dev->hotkey_event_type); error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL); if (error) - goto err_free_dev; + goto err_null_dev; /* * For some machines the SCI responsible for providing hotkey @@ -2811,13 +2824,19 @@ static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev) if (ec_handle && acpi_has_method(ec_handle, "NTFY")) { INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work); + error = devm_add_action(parent, + toshiba_acpi_cancel_hotkey_work, + &dev->hotkey_work); + if (error) + return error; + error = i8042_install_filter(toshiba_acpi_i8042_filter); if (error) { pr_err("Error installing key filter\n"); - goto err_free_dev; + return error; } - dev->ntfy_supported = 1; + ntfy_supported = true; } /* @@ -2840,13 +2859,19 @@ static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev) goto err_remove_filter; } + if (ntfy_supported) { + error = devm_add_action(parent, + toshiba_acpi_i8042_remove_filter, + NULL); + goto err_remove_filter; + } + return 0; - err_remove_filter: - if (dev->ntfy_supported) +err_remove_filter: + if (ntfy_supported) i8042_remove_filter(toshiba_acpi_i8042_filter); - err_free_dev: - input_free_device(dev->hotkey_dev); +err_null_dev: dev->hotkey_dev = NULL; return error; } @@ -2974,14 +2999,6 @@ static int toshiba_acpi_remove(struct acpi_device *acpi_dev) sysfs_remove_group(&dev->acpi_dev->dev.kobj, &toshiba_attr_group); - if (dev->ntfy_supported) { - i8042_remove_filter(toshiba_acpi_i8042_filter); - cancel_work_sync(&dev->hotkey_work); - } - - if (dev->hotkey_dev) - input_unregister_device(dev->hotkey_dev); - backlight_device_unregister(dev->backlight_dev); led_classdev_unregister(&dev->led_dev); @@ -3080,7 +3097,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev) dev->kbd_function_keys_supported = !ret; dev->hotkey_event_type = 0; - if (toshiba_acpi_setup_keyboard(dev)) + if (toshiba_acpi_setup_keyboard(parent, dev)) pr_info("Unable to activate hotkeys\n"); /* Determine whether or not BIOS supports transflective backlight */ From patchwork Wed Mar 24 12:55:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12161051 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E445C433F7 for ; Wed, 24 Mar 2021 12:57:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E12861A0B for ; Wed, 24 Mar 2021 12:57:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234546AbhCXM4j (ORCPT ); Wed, 24 Mar 2021 08:56:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234574AbhCXM4G (ORCPT ); Wed, 24 Mar 2021 08:56:06 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91160C0613E1 for ; Wed, 24 Mar 2021 05:56:06 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id h10so27455183edt.13 for ; Wed, 24 Mar 2021 05:56:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gTwIvnFJ6UsqMLEIUtmaMXWTcL1Cr8qDnDvFwxUlyRo=; b=bmsC/KwYkIzuvFP7Idgwv5+p6kgC9Ye8LKkbjNEhX+tq2iw90b48JioM/uXs8qGp/j 7yfjdIrCmrv2sB6OFf7M/FkpXYW7wjcT250s9W0gpygqFAd/vs/vdAD5FiiMWDwwNaTp OJgN+VCaAK4AniCbsqmqMkoi02XTfkzi4z/5KDgEaiJotbunvsNjL6+KH7x2+mBaXm3k Vt5Rq5QBnW9eCfp/6ToIbwu4YojnHMXcjCHciJl5BWnrEhHfyXAJD+pfJu6vho1VyuF+ z07Xlox0xuiuC7pl3CAuzlGy+jeFgHtaYJACRudvls1IjhT5jCVEOqQRpigkXONRBI3Q rSIA== 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=gTwIvnFJ6UsqMLEIUtmaMXWTcL1Cr8qDnDvFwxUlyRo=; b=YJEInUvKTMrQZeujs3ZnppqXKLGtCP4+0FC1X2gcK7VBxirXsZYgT2JFwLqHD19NyS cw4p9RtPGd6VgATFlC/SMsKtEsNInwB7YjUAeSSfgtb+l7L96GwEMX2uccxkNYryMQCt Q8EchDOv3VTO/RSANNtJaaT0ykTmaQGgH7g5LEzE63J+2QyqFF0xyixHbwK4dEyrPz0T bm2sRVM3QwL+/pOveklGodxDMS3Ds1A5NS2GIXEmCm9AMtSrVbAYMt6QVRkJBsr+4AUp TqWJkNqz1ZxNXJLlZb9Bdi7IXjju41WDlKIPgdXPMH/3gT9Vvi83mc+h8X2Z1hdXz/0a jKbQ== X-Gm-Message-State: AOAM530pIY+zOWOP3UeX4WYErACMHJnG6PnrkGEVUcGgeaWKJKT1gdxN uvhq+JyHv7VB4J4Ep8rTvebbEg== X-Google-Smtp-Source: ABdhPJyN5wrrs/ArU3voReZNJqPglYS2Zo/b32kuE6YTrDfhRKFB4Ch90AD8q0CTaav6C8DazMTz/w== X-Received: by 2002:a05:6402:51cd:: with SMTP id r13mr3347222edd.116.1616590565316; Wed, 24 Mar 2021 05:56:05 -0700 (PDT) Received: from localhost.localdomain ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id fi11sm880282ejb.73.2021.03.24.05.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 05:56:05 -0700 (PDT) From: Alexandru Ardelean To: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org Cc: coproscefalo@gmail.com, hdegoede@redhat.com, mgross@linux.intel.com, jic23@kernel.org, linux@deviqon.com, Alexandru Ardelean Subject: [PATCH 05/10] platform/x86: toshiba_acpi: register backlight with device-managed variant Date: Wed, 24 Mar 2021 14:55:43 +0200 Message-Id: <20210324125548.45983-6-aardelean@deviqon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324125548.45983-1-aardelean@deviqon.com> References: <20210324125548.45983-1-aardelean@deviqon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This change converts the registration of the backlight data with the devm_backlight_device_register() function. This way, the backlight_device_unregister() call is no longer required, and the order of deregistration is made to be more symmetrical with the registration order. Signed-off-by: Alexandru Ardelean Reviewed-by: Jonathan Cameron --- drivers/platform/x86/toshiba_acpi.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index 556f2cc99bad..ada2a2d8c913 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -2876,7 +2876,8 @@ static int toshiba_acpi_setup_keyboard(struct device *parent, return error; } -static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev) +static int toshiba_acpi_setup_backlight(struct device *parent, + struct toshiba_acpi_dev *dev) { struct backlight_properties props; int brightness; @@ -2924,11 +2925,12 @@ static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev) if (dev->tr_backlight_supported) props.max_brightness++; - dev->backlight_dev = backlight_device_register("toshiba", - &dev->acpi_dev->dev, - dev, - &toshiba_backlight_data, - &props); + dev->backlight_dev = devm_backlight_device_register(parent, + "toshiba", + &dev->acpi_dev->dev, + dev, + &toshiba_backlight_data, + &props); if (IS_ERR(dev->backlight_dev)) { ret = PTR_ERR(dev->backlight_dev); pr_err("Could not register toshiba backlight device\n"); @@ -2999,8 +3001,6 @@ static int toshiba_acpi_remove(struct acpi_device *acpi_dev) sysfs_remove_group(&dev->acpi_dev->dev.kobj, &toshiba_attr_group); - backlight_device_unregister(dev->backlight_dev); - led_classdev_unregister(&dev->led_dev); led_classdev_unregister(&dev->kbd_led); led_classdev_unregister(&dev->eco_led); @@ -3104,9 +3104,9 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev) ret = get_tr_backlight_status(dev, &dummy); dev->tr_backlight_supported = !ret; - ret = toshiba_acpi_setup_backlight(dev); + ret = toshiba_acpi_setup_backlight(parent, dev); if (ret) - goto error; + return ret; toshiba_illumination_available(dev); if (dev->illumination_supported) { From patchwork Wed Mar 24 12:55:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12161045 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 442D9C433DB for ; Wed, 24 Mar 2021 12:57:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B92661A11 for ; Wed, 24 Mar 2021 12:57:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234574AbhCXM4j (ORCPT ); Wed, 24 Mar 2021 08:56:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234586AbhCXM4I (ORCPT ); Wed, 24 Mar 2021 08:56:08 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95332C0613DF for ; Wed, 24 Mar 2021 05:56:07 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id hq27so32680320ejc.9 for ; Wed, 24 Mar 2021 05:56:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Xslj2HthXDrqOB8fzPzGxoP+4g8oF5kFhH9tLbOpuwk=; b=EA/iiRLzhPyouBzEGqEEvNayjzGltHlqtlmPvlamFkf9kwv39A8FvLmv37bHb4Ce4P BmDt+qmivDvxZEKbSlPitksLF3DqE4iX4QXgkJtMo14lpGJBiVzlWMDiZlfS62p6922P 4J7CbykQTUMs2xQnVspOJTy5D2sX6PymEpgCVL/RGIf9ONuHHmPBaglU5kmmINmKgfMi FrVfMouBnq1rDRaUCBRbzgG4lCW+k2KEqXWmOqmo0Sepc+xKR/V+sdEe+OtFGkKu0xgT UBeySBlvXwSoa7meSHqZrtZ6f1mTAyGtTK4krut44NH4dUWZMG3lWhqiAlD+lrHH0BXs 3vNA== 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=Xslj2HthXDrqOB8fzPzGxoP+4g8oF5kFhH9tLbOpuwk=; b=ATGBwVo9I1AG9UlluNFDxOSKPSF7JYn17x8P1MoRYhRqpjJgoywXmjEpgsp2a+4h/C 4cVXOyhv4t0fgtTTGlK6gwZl7QkpKiEI0mUMd4FcijAU0YAeuxJ68IO6vX3G2uKEcsMy oUzsZMbmrpFutC0nCOb/oxyJB7XF1N+aqkNNcsfn3uQZl1NJIayEtsHrAdCHXYaIotme 4X+stJ4lDFAZv6g+zuhsacYMZAV9augjd67GO285aIpmGQxQtJeRrZ8aEHBPjInUbDg5 erbcARzeL2C0mHY5wOlYlaihUCEOXdLCKv4dVSiMKfOpqzdHsW9t+gxa+fmY8mYOddVr X2wQ== X-Gm-Message-State: AOAM531G2eofwPzefB0bHTnQmbi+LbXggj7bxzG9nLheNdaVni68gsqQ rwJKPXdKjQq9hn7Uq8ys/q1cIg== X-Google-Smtp-Source: ABdhPJx2EOP9+eIwQbX5mIZcz9HFnp6uZundPHwJXDNQuVzbLvxvvM5eF6ZIv3J5LAFVfjhQ9AR/ZA== X-Received: by 2002:a17:906:3952:: with SMTP id g18mr3556682eje.104.1616590566405; Wed, 24 Mar 2021 05:56:06 -0700 (PDT) Received: from localhost.localdomain ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id fi11sm880282ejb.73.2021.03.24.05.56.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 05:56:06 -0700 (PDT) From: Alexandru Ardelean To: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org Cc: coproscefalo@gmail.com, hdegoede@redhat.com, mgross@linux.intel.com, jic23@kernel.org, linux@deviqon.com, Alexandru Ardelean Subject: [PATCH 06/10] platform/x86: toshiba_acpi: use devm_led_classdev_register() for LEDs Date: Wed, 24 Mar 2021 14:55:44 +0200 Message-Id: <20210324125548.45983-7-aardelean@deviqon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324125548.45983-1-aardelean@deviqon.com> References: <20210324125548.45983-1-aardelean@deviqon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org With this change the deregistration of the LED objects is made symmetrical (and in reverse) with the registration. We also can get rid of the calls to led_classdev_unregister(), because the LED objects will be cleaned up when the reference to the parent device object goes to zero. This change also unifies the reference to the parent object from '&acpi_dev->dev' and '&dev->acpi_dev->dev' to 'parent', since it's the same reference, and makes the code-lines a bit shorter. Signed-off-by: Alexandru Ardelean Reviewed-by: Jonathan Cameron --- drivers/platform/x86/toshiba_acpi.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index ada2a2d8c913..e787c140eec2 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -3001,10 +3001,6 @@ static int toshiba_acpi_remove(struct acpi_device *acpi_dev) sysfs_remove_group(&dev->acpi_dev->dev.kobj, &toshiba_attr_group); - led_classdev_unregister(&dev->led_dev); - led_classdev_unregister(&dev->kbd_led); - led_classdev_unregister(&dev->eco_led); - if (dev->wwan_rfk) { rfkill_unregister(dev->wwan_rfk); rfkill_destroy(dev->wwan_rfk); @@ -3114,7 +3110,9 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev) dev->led_dev.max_brightness = 1; dev->led_dev.brightness_set = toshiba_illumination_set; dev->led_dev.brightness_get = toshiba_illumination_get; - led_classdev_register(&acpi_dev->dev, &dev->led_dev); + ret = devm_led_classdev_register(parent, &dev->led_dev); + if (ret) + return ret; } toshiba_eco_mode_available(dev); @@ -3123,7 +3121,9 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev) dev->eco_led.max_brightness = 1; dev->eco_led.brightness_set = toshiba_eco_mode_set_status; dev->eco_led.brightness_get = toshiba_eco_mode_get_status; - led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led); + ret = devm_led_classdev_register(parent, &dev->eco_led); + if (ret) + return ret; } toshiba_kbd_illum_available(dev); @@ -3139,7 +3139,9 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev) dev->kbd_led.max_brightness = 1; dev->kbd_led.brightness_set = toshiba_kbd_backlight_set; dev->kbd_led.brightness_get = toshiba_kbd_backlight_get; - led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led); + ret = devm_led_classdev_register(parent, &dev->kbd_led); + if (ret) + return ret; } ret = toshiba_touchpad_get(dev, &dummy); From patchwork Wed Mar 24 12:55:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12161055 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E859BC43381 for ; Wed, 24 Mar 2021 12:57:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CCF8961A0D for ; Wed, 24 Mar 2021 12:57:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234815AbhCXM4k (ORCPT ); Wed, 24 Mar 2021 08:56:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234593AbhCXM4J (ORCPT ); Wed, 24 Mar 2021 08:56:09 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FBF9C0613E0 for ; Wed, 24 Mar 2021 05:56:08 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id y6so27529226eds.1 for ; Wed, 24 Mar 2021 05:56:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ruo6fYyWvyeJFaVWRfRo7oSi7ED8tQGcfoAxMCBCouU=; b=pToGEiEfgiNyZfl5C5BwyI33D499QdsgN5d4sYrAyvneIIsK/sYBAGjJZrICh9FW3g ltW9Mx8eY0dcmwNGjyTEPcdR9Dx0lfN3skiPB61+AvuKuVXuIB1vG5gF6N0PVrbK+V2d DdrBpkOc5Oc3lAazjRDt8f0l4wKevp/U8+82KBYfgfV8JRJnfBIwkV8w4n2qHGLT/qqw m635iR/BBo/0bSiWsebp3FGP9+gM7BAhr9HXzP7tXV/O3XnnfzLp1O49EzdO4pkb9+Bw AJ5q+u8K7rnnwi+Dl1NA3M0i5lZvPul7SbJbu9QuQOfjKteIHLWGMpLvFxkxWLBVTXgr 5/uA== 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=Ruo6fYyWvyeJFaVWRfRo7oSi7ED8tQGcfoAxMCBCouU=; b=AzK7wDnEEQlV7Mxr5AhkpPVwxDUuBHFlL9F7i+oNCiFsi1169dOa9mx35rpxxnP3ds F+tCCDoo8hQXu2KNz3XiW7pWMDZETN6aHgFRuF4f+H9dlR3lt5IfOp83kArNnaIKu+7m XXuJzSt1KUoAkKfx8cQdANi5bGdZMAeTaGkVdDLrX1zhC6BYNnwLgDOuMkr3E+iFDKGD hSB4DsVhtBBcr8uK7S/tjH0cl6bXHQWjApnWHLTEvTdYp5uMTyxYWUUd8XZmqeDowanV CaKXjS23q2WwG/0d+/39UKnFUXFw8ikEjTVS04E3scMiaRAnReVFodbGWeJAekwkN5YT 3bVw== X-Gm-Message-State: AOAM532aNwFoOh9o2W/HhLo5MwZkQNctHm/jVz6/HfPH4cK9QaJ/zgK/ BMNVzy6AY7UojRgDzhsYgoHhKQ== X-Google-Smtp-Source: ABdhPJxJui6LdwmCfMr51Xk8gBZNOfiV50TbD4aKH9VG4B65APB61qzksR3QKrC4/mmIV44+rkV7og== X-Received: by 2002:a05:6402:142:: with SMTP id s2mr3307510edu.2.1616590567384; Wed, 24 Mar 2021 05:56:07 -0700 (PDT) Received: from localhost.localdomain ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id fi11sm880282ejb.73.2021.03.24.05.56.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 05:56:07 -0700 (PDT) From: Alexandru Ardelean To: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org Cc: coproscefalo@gmail.com, hdegoede@redhat.com, mgross@linux.intel.com, jic23@kernel.org, linux@deviqon.com, Alexandru Ardelean Subject: [PATCH 07/10] platform/x86: toshiba_acpi: use device-managed functions for accelerometer Date: Wed, 24 Mar 2021 14:55:45 +0200 Message-Id: <20210324125548.45983-8-aardelean@deviqon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324125548.45983-1-aardelean@deviqon.com> References: <20210324125548.45983-1-aardelean@deviqon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This change converts the IIO registration to use devm_iio_device_alloc() and devm_iio_device_register(). With this change we can remove the manual deregistrations an freeing of the IIO data. This also makes the deregistration symmetrical with the registration. One side-effect (that is undesired), is that if devm_iio_device_register() fails, then the IIO object will not be free'd and will stick around until the parent object is free'd. This is because there is no devm_iio_device_free() function anymore in IIO. However, this is a pretty bad corner-case that should not happen under normal operation. Signed-off-by: Alexandru Ardelean Reviewed-by: Jonathan Cameron --- drivers/platform/x86/toshiba_acpi.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index e787c140eec2..12860ef60e4d 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -2992,11 +2992,6 @@ static int toshiba_acpi_remove(struct acpi_device *acpi_dev) remove_toshiba_proc_entries(dev); - if (dev->accelerometer_supported && dev->indio_dev) { - iio_device_unregister(dev->indio_dev); - iio_device_free(dev->indio_dev); - } - if (dev->sysfs_created) sysfs_remove_group(&dev->acpi_dev->dev.kobj, &toshiba_attr_group); @@ -3149,7 +3144,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev) toshiba_accelerometer_available(dev); if (dev->accelerometer_supported) { - dev->indio_dev = iio_device_alloc(&acpi_dev->dev, sizeof(*dev)); + dev->indio_dev = devm_iio_device_alloc(parent, sizeof(*dev)); if (!dev->indio_dev) { pr_err("Unable to allocate iio device\n"); goto iio_error; @@ -3164,10 +3159,10 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev) dev->indio_dev->num_channels = ARRAY_SIZE(toshiba_iio_accel_channels); - ret = iio_device_register(dev->indio_dev); + ret = devm_iio_device_register(parent, dev->indio_dev); if (ret < 0) { pr_err("Unable to register iio device\n"); - iio_device_free(dev->indio_dev); + dev->indio_dev = NULL; } } iio_error: From patchwork Wed Mar 24 12:55:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12161047 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A293C433F2 for ; Wed, 24 Mar 2021 12:57:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7623561A14 for ; Wed, 24 Mar 2021 12:57:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234593AbhCXM4l (ORCPT ); Wed, 24 Mar 2021 08:56:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234614AbhCXM4K (ORCPT ); Wed, 24 Mar 2021 08:56:10 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D5EAC0613E3 for ; Wed, 24 Mar 2021 05:56:09 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id h10so27455377edt.13 for ; Wed, 24 Mar 2021 05:56:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5b4aQ508Io3+0QcWegMSXE+w4jq/XwA5f3VwTDm7+CM=; b=kPAESwGyeqxafo+DnvdLNonf1MxYA0W8rt++k4+tTM0QMkoVWACB1as0tIafLR7YPL V62xqME1LmZj7DnK1VArZ1fIBbN+Zs7KuM2iqdeosqtcHe4WHBmgGsYKZ6KTKmS312Af nSXgDeCOdOR5xeBYbjOlhLgYiTlmP9/Zy2c82nEOofFDlKFFkn6ke8npsr0RmQuFpA3v bL7e0zT3YHEPn/4PHCPJAMOPevARu3dHvBI3VFGzIL1847v1av+P+LlY+czh4F72yx9/ dRK69U3EPe5f6fX9RCi2PYl7eWfAyL/sx105I5bXKAbGyKwLD8p2XVPKuqSBeYI+KbF7 op4g== 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=5b4aQ508Io3+0QcWegMSXE+w4jq/XwA5f3VwTDm7+CM=; b=geqaBMQJV/Og93tzGiu0nytTSBbvFe8YNnwR1fUx4KzX9ZjI95JDrfvdGJoMxL507U JE3TODTEXB7pi5YDJ2sjLNuceXwdIojXQBC6EVa95YBBYAGGv36vQpWLKTywIeD5BFzV 3ZNVeTen97COauAKhfjcMKGMROIAD5TXDyd4DdXC7fY3NETk4MBeRt4V7/j+PHLdvhwM ytTLgKgUhvaPKRthHWHroIJ+NMFtjAvvqJ0mWv6qrf5odQ7JLNXxr8jTWM2XpK9y5/Nk 8qbWr2cUZKdCav5Lff1BHAjir867ZAuWdcsi1d69oCvAam+XMysGttgPr9anEKh993Fj 2ZCw== X-Gm-Message-State: AOAM532zkpGypEACDEpezsNDaSFXsEjYA5+Pgp5eMZE3ZymG7Bt4JrtJ 49jxjrPHezLdabdu8FTaEw8SHBE6oZEApKJD X-Google-Smtp-Source: ABdhPJxsSAiGJmL649dJDQw4Ag16alHr4nvmdoimmmdE27PdMGxU9yPAzPpZEvqfxGs5TmtWmDSLZQ== X-Received: by 2002:a50:ec0e:: with SMTP id g14mr3346589edr.264.1616590568409; Wed, 24 Mar 2021 05:56:08 -0700 (PDT) Received: from localhost.localdomain ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id fi11sm880282ejb.73.2021.03.24.05.56.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 05:56:08 -0700 (PDT) From: Alexandru Ardelean To: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org Cc: coproscefalo@gmail.com, hdegoede@redhat.com, mgross@linux.intel.com, jic23@kernel.org, linux@deviqon.com, Alexandru Ardelean Subject: [PATCH 08/10] platform/x86: toshiba_acpi: use device-managed for wwan_rfkill management Date: Wed, 24 Mar 2021 14:55:46 +0200 Message-Id: <20210324125548.45983-9-aardelean@deviqon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324125548.45983-1-aardelean@deviqon.com> References: <20210324125548.45983-1-aardelean@deviqon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This change converts the wwan_rfkill object to be free'd automatically when the parent refcount goes to zero. There are 2 cleanup operations required: rfkill_unregister() and rfkill_destroy(). Since they don't have any devm_ variants, they are hooked via devm_add_action_or_reset(). The main reason to do this is to enforce ordering on cleanup, when the Toshiba ACPI device is cleaned up. Signed-off-by: Alexandru Ardelean Reviewed-by: Jonathan Cameron --- drivers/platform/x86/toshiba_acpi.c | 40 ++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index 12860ef60e4d..a1249f6dde9a 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -2591,7 +2591,22 @@ static const struct rfkill_ops wwan_rfk_ops = { .poll = toshiba_acpi_wwan_poll, }; -static int toshiba_acpi_setup_wwan_rfkill(struct toshiba_acpi_dev *dev) +static void toshiba_acpi_rfkill_destroy(void *data) +{ + struct rfkill *wwan_rfk = data; + + rfkill_destroy(wwan_rfk); +} + +static void toshiba_acpi_rfkill_unreg(void *data) +{ + struct rfkill *wwan_rfk = data; + + rfkill_unregister(wwan_rfk); +} + +static int toshiba_acpi_setup_wwan_rfkill(struct device *parent, + struct toshiba_acpi_dev *dev) { int ret = toshiba_wireless_status(dev); @@ -2608,15 +2623,27 @@ static int toshiba_acpi_setup_wwan_rfkill(struct toshiba_acpi_dev *dev) return -ENOMEM; } + ret = devm_add_action_or_reset(parent, toshiba_acpi_rfkill_destroy, + dev->wwan_rfk); + if (ret) + return ret; + rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch); ret = rfkill_register(dev->wwan_rfk); if (ret) { pr_err("Unable to register WWAN rfkill device\n"); - rfkill_destroy(dev->wwan_rfk); + return ret; } - return ret; + ret = devm_add_action_or_reset(parent, toshiba_acpi_rfkill_unreg, + dev->wwan_rfk); + if (ret) { + dev->wwan_rfk = NULL; + return ret; + } + + return 0; } /* @@ -2996,11 +3023,6 @@ static int toshiba_acpi_remove(struct acpi_device *acpi_dev) sysfs_remove_group(&dev->acpi_dev->dev.kobj, &toshiba_attr_group); - if (dev->wwan_rfk) { - rfkill_unregister(dev->wwan_rfk); - rfkill_destroy(dev->wwan_rfk); - } - return 0; } @@ -3189,7 +3211,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev) toshiba_wwan_available(dev); if (dev->wwan_supported) - toshiba_acpi_setup_wwan_rfkill(dev); + toshiba_acpi_setup_wwan_rfkill(parent, dev); toshiba_cooling_method_available(dev); From patchwork Wed Mar 24 12:55:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12161049 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4635BC43445 for ; Wed, 24 Mar 2021 12:57:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 21D1061A11 for ; Wed, 24 Mar 2021 12:57:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234614AbhCXM4l (ORCPT ); Wed, 24 Mar 2021 08:56:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234642AbhCXM4L (ORCPT ); Wed, 24 Mar 2021 08:56:11 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A87C5C0613E4 for ; Wed, 24 Mar 2021 05:56:10 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id h10so27455459edt.13 for ; Wed, 24 Mar 2021 05:56:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Yr+hqksGhsoym9OCme5jUvwyeFtwCUa6Az4rur4J9Ag=; b=d1Hl+i0+A5Tve+esaspvDfy3ewi9VbVCtugdJQn0K1QWqY+FGWio3cXwpC7Y5TSQmb CAZbREkS4JI5YXjkYuuBEs3n6kd09gpj3KnlxvdNaHRAp2OgrLdRvvUhlbM46RaHyGnU mKANrSt2KGlLDwDn7rEBHMlOwIwN19zUX+/7EvKukLVv5Ku0uh89Er0X9omSScL4/nIe 7j3ILSGNXewnknpaIG6j8xNuBUE/M9KN9/57LVC1rEHh2Cw1QnckIZST8W7Ur4RZ9Vrx vqNBC1+J5k8AlrzMWHjFH4Q5jpfBuj/yNGu01EozxvWJn1TU/dzgaNgUynTiC33iG8id isfg== 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=Yr+hqksGhsoym9OCme5jUvwyeFtwCUa6Az4rur4J9Ag=; b=DCm8vTV63PyyCgQBd9wI7k0X5jYHQ2yo6KnKHn74ctt9fsP2nJpay4YbEbOAq8yXRj Umyuu17cvUo7El+ZMklWELC6+T/kMYOAFEuVLmO/Zk2a2NfR9g/4+boItuWH+JhxtPyJ e5Uo6xqrsYWsKXvOxnoNjEGRGW8VdN4g1ESi3nNXoABZETYlDh0M5u1wMlhF4LZew0kQ bTogSDoARXmzNfjcZAA4osWZb+s1FjEHjydYxyZh1GStQdkFOPovI2/4DhcX2b8G7Aev 8Mhumls81HlS1v419plkf0P/nkJ84jvF0ed23iCGjqfD9Ic9SZ8DwmnM6guGjr9lX5IF CjVQ== X-Gm-Message-State: AOAM5332pZmUN6yh7piknQP2yWL93ZPiVpfTDYygyRtCCbnNTJKyWy32 nxPSZVfspzbxm2ZVV++iPxJTIg== X-Google-Smtp-Source: ABdhPJxIcmTmkmMN9WvwQrOU///P6BOxa5oEnluuOV54BfqppfMs+765Gs7vq6TYuoCyYNuyKS4u5g== X-Received: by 2002:aa7:d416:: with SMTP id z22mr3222861edq.239.1616590569433; Wed, 24 Mar 2021 05:56:09 -0700 (PDT) Received: from localhost.localdomain ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id fi11sm880282ejb.73.2021.03.24.05.56.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 05:56:09 -0700 (PDT) From: Alexandru Ardelean To: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org Cc: coproscefalo@gmail.com, hdegoede@redhat.com, mgross@linux.intel.com, jic23@kernel.org, linux@deviqon.com, Alexandru Ardelean Subject: [PATCH 09/10] platform/x86: toshiba_acpi: use device-managed for sysfs removal Date: Wed, 24 Mar 2021 14:55:47 +0200 Message-Id: <20210324125548.45983-10-aardelean@deviqon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324125548.45983-1-aardelean@deviqon.com> References: <20210324125548.45983-1-aardelean@deviqon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This change moves the creation of the Toshiba ACPI group to be automatically removed when the parent refcount goes to zero. The main reason to do this, is to also enforce that the order of removal is mirroring the order of initialization. Signed-off-by: Alexandru Ardelean Reviewed-by: Jonathan Cameron --- drivers/platform/x86/toshiba_acpi.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index a1249f6dde9a..8e8917979047 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -200,7 +200,6 @@ struct toshiba_acpi_dev { unsigned int usb_three_supported:1; unsigned int wwan_supported:1; unsigned int cooling_method_supported:1; - unsigned int sysfs_created:1; unsigned int special_functions; bool kbd_event_generated; @@ -3019,10 +3018,6 @@ static int toshiba_acpi_remove(struct acpi_device *acpi_dev) remove_toshiba_proc_entries(dev); - if (dev->sysfs_created) - sysfs_remove_group(&dev->acpi_dev->dev.kobj, - &toshiba_attr_group); - return 0; } @@ -3049,6 +3044,13 @@ static void toshiba_acpi_misc_deregister(void *data) misc_deregister(miscdev); } +static void toshiba_acpi_sysfs_remove(void *data) +{ + struct kobject *kobj = data; + + sysfs_remove_group(kobj, &toshiba_attr_group); +} + static int toshiba_acpi_add(struct acpi_device *acpi_dev) { struct device *parent = &acpi_dev->dev; @@ -3219,21 +3221,20 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev) ret = sysfs_create_group(&dev->acpi_dev->dev.kobj, &toshiba_attr_group); - if (ret) { - dev->sysfs_created = 0; - goto error; - } - dev->sysfs_created = !ret; + if (ret) + return ret; + + ret = devm_add_action_or_reset(parent, + toshiba_acpi_sysfs_remove, + &dev->acpi_dev->dev.kobj); + if (ret) + return ret; create_toshiba_proc_entries(dev); toshiba_acpi = dev; return 0; - -error: - toshiba_acpi_remove(acpi_dev); - return ret; } static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event) From patchwork Wed Mar 24 12:55:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 12161053 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27B66C43446 for ; Wed, 24 Mar 2021 12:57:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0605161A0D for ; Wed, 24 Mar 2021 12:57:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234642AbhCXM4m (ORCPT ); Wed, 24 Mar 2021 08:56:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234651AbhCXM4O (ORCPT ); Wed, 24 Mar 2021 08:56:14 -0400 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFEF1C0613E7 for ; Wed, 24 Mar 2021 05:56:11 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id e7so27428766edu.10 for ; Wed, 24 Mar 2021 05:56:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=B0AOixSVQaYDeSh4VAk4nqi8IzY0YDC7YSX2q7F9wac=; b=p9eNAslDD0sBoEN0CD3Yw/zgILE+kMoGorL0VgdHYiQdT0rhKS7z0mnChro/Q65BKR NkS+yM2dzXDwfu4cOc0CPT0U1y8uvWyr8ByPMvt1oqsuaOOrJQEd4nDolh0XGFqVhBDA yBpb2ID4TQAmaDwla+ifXgdHfEs+VISkqxpvMhqAL/YN2OKehtffFRFiQFU/cigw2xDV dQA+lqyD+8Bj1DjgDe8uHGksSE2VX7/0KNsg6tXjBoj53mvSqZlZtaa1UDfa4hK3/PWF MQwCO5fKiNW1VuopEa9RmH3upnQ0smbXMGoaHlie2wAl4KBM4G9VSNXs7CuUxHxAWc7q /Byg== 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=B0AOixSVQaYDeSh4VAk4nqi8IzY0YDC7YSX2q7F9wac=; b=QNxMi84avUIDlnxjm8Dz4wNMpMcOIVk7UdiTGD340LisgQ9GqQm3+p2P9wOttms6e2 BtssZe9+fxLi2/xiunh+gLlv0exsaxCCgskYRtDkEkfS+Q8SbVTLjxGyscwO5WRRkSGu Vw1sx1bpwGVxc1P62A6k2bYapujCUsoOyFHrJpN5jJFj6qxm6s0MxBHaIkOQkCWqC2XS ELWCNRbMUF4CFzwBgGtCU56ft/iFtWhkG98C6dEqj9xF3sbh7zHoXmwyugw7qwcrmoLD 2Zjy/OnygBKOiaHhYI4NonlpeLsRHzO+JL4h09AqN/dLspJ9nc7SK1iBH2sHQrPPlePg nw2A== X-Gm-Message-State: AOAM531rR00Ss8UVpm3whWaoEVog3PDDilcv3ulGAoBYJ4+1V3Z44sdi 1L+qOWqvxuBVWtYFHdWG0cfL0g== X-Google-Smtp-Source: ABdhPJzcWnvJEq/xcup+eZznQQjcwhSGHwksnhZO04Sbq0tuTKJTYhTUo/ehIeYEdYC6gE8DgEOhxQ== X-Received: by 2002:aa7:d9c8:: with SMTP id v8mr3212277eds.9.1616590570503; Wed, 24 Mar 2021 05:56:10 -0700 (PDT) Received: from localhost.localdomain ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id fi11sm880282ejb.73.2021.03.24.05.56.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 05:56:10 -0700 (PDT) From: Alexandru Ardelean To: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org Cc: coproscefalo@gmail.com, hdegoede@redhat.com, mgross@linux.intel.com, jic23@kernel.org, linux@deviqon.com, Alexandru Ardelean Subject: [PATCH 10/10] platform/x86: toshiba_acpi: bind proc entries creation to parent Date: Wed, 24 Mar 2021 14:55:48 +0200 Message-Id: <20210324125548.45983-11-aardelean@deviqon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210324125548.45983-1-aardelean@deviqon.com> References: <20210324125548.45983-1-aardelean@deviqon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This change binds the creation of the proc entries to the parent object, via the devm_add_action_or_reset() call. This way when the parent object's refcount goes to zero, the proc entries are removed in the reverse other in which they were created. This is the last bit of the toshiba_acpi_remove() function, so in this change this function is removed. Signed-off-by: Alexandru Ardelean Reviewed-by: Jonathan Cameron --- drivers/platform/x86/toshiba_acpi.c | 45 ++++++++++++++--------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index 8e8917979047..56ee5cd1e90c 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -1671,7 +1671,23 @@ static int __maybe_unused version_proc_show(struct seq_file *m, void *v) #define PROC_TOSHIBA "toshiba" -static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev) +static void remove_toshiba_proc_entries(void *data) +{ + struct toshiba_acpi_dev *dev = data; + + if (dev->backlight_dev) + remove_proc_entry("lcd", toshiba_proc_dir); + if (dev->video_supported) + remove_proc_entry("video", toshiba_proc_dir); + if (dev->fan_supported) + remove_proc_entry("fan", toshiba_proc_dir); + if (dev->hotkey_dev) + remove_proc_entry("keys", toshiba_proc_dir); + remove_proc_entry("version", toshiba_proc_dir); +} + +static int create_toshiba_proc_entries(struct device *parent, + struct toshiba_acpi_dev *dev) { if (dev->backlight_dev) proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir, @@ -1687,19 +1703,8 @@ static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev) &keys_proc_ops, dev); proc_create_single_data("version", S_IRUGO, toshiba_proc_dir, version_proc_show, dev); -} -static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev) -{ - if (dev->backlight_dev) - remove_proc_entry("lcd", toshiba_proc_dir); - if (dev->video_supported) - remove_proc_entry("video", toshiba_proc_dir); - if (dev->fan_supported) - remove_proc_entry("fan", toshiba_proc_dir); - if (dev->hotkey_dev) - remove_proc_entry("keys", toshiba_proc_dir); - remove_proc_entry("version", toshiba_proc_dir); + return devm_add_action_or_reset(parent, remove_toshiba_proc_entries, dev); } static const struct backlight_ops toshiba_backlight_data = { @@ -3012,15 +3017,6 @@ static void print_supported_features(struct toshiba_acpi_dev *dev) pr_cont("\n"); } -static int toshiba_acpi_remove(struct acpi_device *acpi_dev) -{ - struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev); - - remove_toshiba_proc_entries(dev); - - return 0; -} - static const char *find_hci_method(acpi_handle handle) { if (acpi_has_method(handle, "GHCI")) @@ -3230,7 +3226,9 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev) if (ret) return ret; - create_toshiba_proc_entries(dev); + ret = create_toshiba_proc_entries(parent, dev); + if (ret) + return ret; toshiba_acpi = dev; @@ -3340,7 +3338,6 @@ static struct acpi_driver toshiba_acpi_driver = { .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS, .ops = { .add = toshiba_acpi_add, - .remove = toshiba_acpi_remove, .notify = toshiba_acpi_notify, }, .drv.pm = &toshiba_acpi_pm,