Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp316412pxf; Wed, 24 Mar 2021 06:00:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3g+0Ys3qKKCAIKefpdunhlNQicA5pb+FYKeTFk4CBdD4MIlsWBTKDJvKUfHBoe3oVcJ+W X-Received: by 2002:a17:906:2551:: with SMTP id j17mr3505255ejb.441.1616590835789; Wed, 24 Mar 2021 06:00:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616590835; cv=none; d=google.com; s=arc-20160816; b=yzwFovLrqwarLM4ajicA6XqbyfjFrG2x9iehj58OacBOHXAZ4ngjH07kPj8Rke6XsS AJL5A4mPgcn4lBgbXPyLAmgFw3PFdV2G3AeAEZOewDQeU7oCzQ2dkEhApj39K7fuc8Lg ZLtyERMsv6YwdCyx6jbRURi8rH5rCtE4vwN5Fr/x0gwpFISjiLvF2aYlgNjxhAm0Zlh6 GLtjR7sAW6x8ESnHvOCssDy9qjAAbcSRtXnxjNUJbgSQg3odQ0UeVZ/AGPgjlvOBoOCf MYBTm1tkjXpM9iImzsZjdJcuUp0l5JeEutezEVOM2bQj+K8QffOnQXeGCO8Jel8zmdUE MEzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5b4aQ508Io3+0QcWegMSXE+w4jq/XwA5f3VwTDm7+CM=; b=gFxM5fsi23usKfVYUkycc/g4Uz0VAxNSTi3KQ7dHcXH3wBGAfVBTaMpv/gE3ynqHTp CUbqTxYb2ETtkCgz24KThFHbWQmjYQ9yDW79C3UDDNhqMZpVgS1upTuMKqcHI9m9SppI RgsA83J/FyQ244uL3m2B5nlclHT4EcTNSGaQVVmTU6F7oeZG3SHZrdBJ51nmyMoVmcSo WPuJMFEJO52V/WZ/nEKiNotFv48o6yoWoBud2IOGrzg2KkmvnOvRFZhO8ZjUaFvQVnjV aYCzSWGwBSCXTMsdJntO7nZer8IfWQ35UGlC12jWdSt3n/0JOnMuj1ugpzV9wVUZV/Sf 7f7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b=kPAESwGy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deviqon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d1si1678309ejz.282.2021.03.24.06.00.13; Wed, 24 Mar 2021 06:00:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b=kPAESwGy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deviqon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235175AbhCXM4y (ORCPT + 99 others); Wed, 24 Mar 2021 08:56:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234616AbhCXM4K (ORCPT ); Wed, 24 Mar 2021 08:56:10 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D4CCC0613DF for ; Wed, 24 Mar 2021 05:56:09 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id bf3so27527018edb.6 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=VzJM8bgf62IRMicg/hF98eRIo0VPT76v7RbfG4bxr3jCn+YMT+GgcX76BVz4iqEEEP 9Y+bckUkRKoe6T2WUxRYxsxsy1QypURMl9+Z/UxkddploYaDCymsOcMUU02FcZGM4NrE NfKhyf/ROAjH48Ts2sLQgi7YHLRq5buROy3R9IE3bmdgOCnCIvNMy3SxV6jyJfiJjTBD 0PbI+mHiF0XLTrOB7hUAROGNGWJ6qahMdLL4OTWgFM82Zma9M5JGmzmABYmWTJokQNZY OicTKnA7Bn7063SX7Hi3q3nGaLaM2NGwpFgqPobMF0hDVKGwzffJZc+Hd3lGe5I0brGL NEMA== X-Gm-Message-State: AOAM531xKMSjz/ehMDfjqoQZPw3nwjqM00aNN1BKOaVjWR2gVpH6VVdH gUFNxmwPknloa/K0TePfetry/A== 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- 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); -- 2.30.2