Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp316137pxf; Wed, 24 Mar 2021 06:00:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5K267dk4x2RxuKHGKuZSjBQG5aRwR7JHZZ0OH+pFx1Llzflcbk1GrEI/KpZLYAwi6tDvU X-Received: by 2002:a17:907:68a:: with SMTP id wn10mr3580619ejb.551.1616590818432; Wed, 24 Mar 2021 06:00:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616590818; cv=none; d=google.com; s=arc-20160816; b=XsvJ4n2QBkfR4kU32Auno+CnJPACY8kT1k1HMOOqv8ihZSSWgBMumeDyxScimYYlje WzSjhH52IbuL28h54FTvQH5pjxCf005tKbFbKoGXuY3coK/bJK/qAndqzvwVs7lgT+mL 7uogZPsryjzV36X9z+5IRdM4Avl+2iu4R8p8furFIgkgrDZpnp7+9B/YMuIrApTzsvYY 96OyRv9M1NnFV2NxP4RqwtxpQQx1p4vxMLO/QUpqe0ayPU+2AX2+kuaKyWHYq7Xh+Kpq H96lTdkq9UpXHqpr7Y+N1NQ5xg4naQyMINXcAzKivRSeUpBTgtqNvSY3jwyAayZR8moy mHVA== 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=UFsO3CjdzjvSKalFHfalsmH1Z1YFNl8tTKEel8RPQ5w=; b=xMul1yH+2LktDmPKgVWPwL2tzJ4OXZnkuwMEKg6UoJpjdOCLXrQCPp6Amy8Q7WJFuo uPkzjFeWlQebTEJNoxaPDL1eX4XkNtx2485QDVQXcG9nVCPGC2SobN1Lp1w4kqWnKuOx byXk9mIKiGSVUktNin27BycfhOYRYuuIs0+Vx0M5SVeVsGBXD320PciNeuK9azG6GAuh ZgpFC++IwTSmhVgOehNoHjuEKrE4cmNPzPAzUiuYPPH0agSqZXrD0V1A0sRngqx/K1C7 rGuqdGRovLoQZD8eD1h2Bw93Vg7BZC6Jk6cKNPnwtuN/nTd6hGb0JBb6m7X+rE9E2Z6d 9K+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b=TQDfwW+R; 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 mj17si1794040ejb.28.2021.03.24.05.59.55; Wed, 24 Mar 2021 06:00:18 -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=TQDfwW+R; 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 S235048AbhCXM4s (ORCPT + 99 others); Wed, 24 Mar 2021 08:56:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234547AbhCXM4G (ORCPT ); Wed, 24 Mar 2021 08:56:06 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 952A1C061763 for ; Wed, 24 Mar 2021 05:56:05 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id u21so14713005ejo.13 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=s0TfkZZV5TD6f9Ilpf8MnxmND9z1vC8INsBrckQT9vexkzOXJ14LEmwP1sL5cnh+zG yTqc0REbiLQGazEK8J2Kewiy4zagF5InMUXdW7lnYDJTK3noLxANzcZPUP1O6Wok+eCE RIKpV20Z9JHfoNFXikWoYc15zu9PTVq9n/Ey7YhmtqKMADhpZqZ719jjj5da/OcUsR75 n2mV2JuWsAKWQSVex6j/7Tq5jbzIryWDCVEeAjaUPPacGQHMbCnjAHEXmVc7pYesiAuk Cco014/0yHxW2u1k9BrQwlmrphG9W4DexKBnR7FIvaIUsGgWAfawqX5r4qNdviFeSZza IzUg== X-Gm-Message-State: AOAM531Hj56gX3NW9n7p/jc/aIpf6z3G715XuVsRKbJoT5X0DLfiICCI IGA3aiVyDPTdoSNBXjRKot7s5A== 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 */ -- 2.30.2