platform/x86: dell-privacy: Add support for Dell hardware privacy
Subsystems (2)
PATCH v6 1/2 platform/x86: dell-privacy: Add support for Dell hardware privacy
From: Perry Yuan <[email protected]>
add support for Dell privacy driver for the Dell units equipped hardware privacy design, which protect users privacy of audio and camera from hardware level. Once the audio or camera privacy mode activated, any applications will not get any audio or video stream when user pressed ctrl+F4 hotkey, audio privacy mode will be enabled, micmute led will be also changed accordingly
The micmute led is fully controlled by hardware & EC(embedded controller) and camera mute hotkey is Ctrl+F9. Currently design only emits SW_CAMERA_LENS_COVER event while the camera lens shutter will be changed by EC & HW(hardware) control
*The flow is like this:
1) User presses key. HW does stuff with this key (timeout timer is started)
2) WMI event is emitted from BIOS to kernel
3) WMI event is received by dell-privacy
4) KEY_MICMUTE emitted from dell-privacy
5) Userland picks up key and modifies kcontrol for SW mute
6) Codec kernel driver catches and calls ledtrig_audio_set, like this:
ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led ? LED_ON :LED_OFF);
7) If "LED" is set to on dell-privacy notifies EC, and timeout is cancelled, HW mic mute activated. If EC not notified, HW mic mute will also be activated when timeout used up, it is just later than active ack
---
v5 -> v6:
* addressed feedback from Hans
* addressed feedback from Pierre
* optimize some debug format with dev_dbg()
* remove platform driver,combined privacy acpi driver into single wmi driver file
* optimize sysfs interface with string added to be more clearly reading v4 -> v5:
* addressed feedback from Randy Dunlap
* addressed feedback from Pierre-Louis Bossart
* rebase to latest 5.12 rc4 upstream kernel
* fix some space alignment problem
v3 -> v4:
* fix format for Kconfig
* add sysfs document
* add flow comments to the privacy wmi/acpi driver
* addressed feedback from Barnabás Pőcze[Thanks very much]
* export privacy_valid to make the global state simpler to query
* fix one issue which will block the dell-laptop driver to load when privacy driver invalid
* addressed feedback from Pierre-Louis Bossart,remove the EC ID match v2 -> v3:
* add sysfs attributes doc
v1 -> v2:
* query EC handle from EC driver directly.
* fix some code style.
* add KEY_END to keymap array.
* clean platform device when cleanup called
* use hexadecimal format for log print in dev_dbg
* remove __set_bit for the report keys from probe.
* fix keymap leak
* add err_free_keymap in dell_privacy_wmi_probe
* wmi driver will be unregistered if privacy_acpi_init() fails
* add sysfs attribute files for user space query.
* add leds micmute driver to privacy acpi
* add more design info the commit info
---
--- .../testing/sysfs-platform-dell-privacy-wmi | 55 +++ drivers/platform/x86/dell/Kconfig | 14 + drivers/platform/x86/dell/Makefile | 1 + drivers/platform/x86/dell/dell-laptop.c | 23 +- drivers/platform/x86/dell/dell-privacy-wmi.c | 441 ++++++++++++++++++ drivers/platform/x86/dell/dell-privacy-wmi.h | 32 ++ drivers/platform/x86/dell/dell-wmi.c | 13 +- 7 files changed, 572 insertions(+), 7 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi create mode 100644 drivers/platform/x86/dell/dell-privacy-wmi.c create mode 100644 drivers/platform/x86/dell/dell-privacy-wmi.h
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +55 -0
@@ -0,0 +1,55 @@ +What: /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/dell_privacy_supported_type +Date: Apr 2021 +KernelVersion: 5.13 +Contact: "[email protected]>" +Description: + Display which dell hardware level privacy devices are supported + “Dell Privacy” is a set of HW, FW, and SW features to enhance + Dell’s commitment to platform privacy for MIC, Camera, and + ePrivacy screens. + The supported hardware privacy devices are: +Attributes: + Microphone Mute: + Identifies the local microphone can be muted by hardware, no applications + is available to capture system mic sound + + Camera Shutter: + Identifies camera shutter controlled by hardware, which is a micromechanical + shutter assembly that is built onto the camera module to block capturing images + from outside the laptop + + supported: + The privacy device is supported by this system + + unsupported: + The privacy device is not supported on this system + + For example to check which privacy devices are supported: + + # cat /sys/bus/wmi/drivers/dell-privacy/6932965F-1671-4CEB-B988-D3AB0A901919/dell_privacy_supported_type + [Microphone Mute] [supported] + [Camera Shutter] [supported] + [ePrivacy Screen] [unsupport] + +What: /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/dell_privacy_current_state +Date: Apr 2021 +KernelVersion: 5.13 +Contact: "[email protected]>" +Description: + Allow user space to check current dell privacy device state. + Describes the Device State class exposed by BIOS which can be + consumed by various applications interested in knowing the Privacy + feature capabilities +Attributes: + muted: + Identifies the privacy device is turned off and cannot send stream to OS applications + + unmuted: + Identifies the privacy device is turned on ,audio or camera driver can get + stream from mic and camera module to OS applications + + For example to check all supported current privacy device states: + + # cat /sys/bus/wmi/drivers/dell-privacy/6932965F-1671-4CEB-B988-D3AB0A901919/dell_privacy_current_state + [Microphone] [unmuted] + [Camera Shutter] [unmuted]
drivers/platform/x86/dell/Kconfig +14 -0
@@ -204,4 +204,18 @@ config DELL_WMI_SYSMAN To compile this driver as a module, choose M here: the module will be called dell-wmi-sysman. +config DELL_PRIVACY + tristate "Dell Hardware Privacy Support" + depends on ACPI + depends on ACPI_WMI + depends on INPUT + depends on DELL_LAPTOP + depends on LEDS_TRIGGER_AUDIO + select DELL_WMI + help + This driver provides integration with the "Dell Hardware Privacy" feature + of Dell laptops. + + To compile this driver as a module, choose M here: the module will + be called dell_privacy. endif # X86_PLATFORM_DRIVERS_DELL
drivers/platform/x86/dell/Makefile +1 -0
@@ -19,3 +19,4 @@ obj-$(CONFIG_DELL_WMI_AIO) += dell-wmi-aio.o obj-$(CONFIG_DELL_WMI_DESCRIPTOR) += dell-wmi-descriptor.o obj-$(CONFIG_DELL_WMI_LED) += dell-wmi-led.o obj-$(CONFIG_DELL_WMI_SYSMAN) += dell-wmi-sysman/ +obj-$(CONFIG_DELL_PRIVACY) += dell-privacy-wmi.o
drivers/platform/x86/dell/dell-laptop.c +17 -6
@@ -31,6 +31,8 @@#include "dell-rbtn.h" #include "dell-smbios.h" +#include "dell-privacy-wmi.h" +struct quirk_entry {bool touchpad_led;bool kbd_led_not_present;
@@ -90,6 +92,7 @@ static struct rfkill *wifi_rfkill;static struct rfkill *bluetooth_rfkill;static struct rfkill *wwan_rfkill;static bool force_rfkill; +static bool has_privacy;module_param (force_rfkill, bool,0444 );MODULE_PARM_DESC (force_rfkill,"enable rfkill on non whitelisted models" );
@@ -2206,10 +2209,16 @@ static int __init dell_init(void)if (dell_smbios_find_token (GLOBAL_MIC_MUTE_DISABLE ) &&dell_smbios_find_token (GLOBAL_MIC_MUTE_ENABLE )) { - micmute_led_cdev.brightness =ledtrig_audio_get (LED_AUDIO_MICMUTE ); - ret =led_classdev_register (&platform_device->dev, &micmute_led_cdev); -if (ret <0 ) - goto fail_led; +if (dell_privacy_has_micmute ()) + has_privacy = true; +else + has_privacy = false; +if (!has_privacy) { + micmute_led_cdev.brightness =ledtrig_audio_get (LED_AUDIO_MICMUTE ); + ret =led_classdev_register (&platform_device->dev, &micmute_led_cdev); +if (ret <0 ) + goto fail_led; + } }if (acpi_video_get_backlight_type () != acpi_backlight_vendor)
@@ -2257,7 +2266,8 @@ static int __init dell_init(void) fail_get_brightness:backlight_device_unregister (dell_backlight_device); fail_backlight: -led_classdev_unregister (&micmute_led_cdev); +if (!has_privacy) +led_classdev_unregister (&micmute_led_cdev); fail_led:dell_cleanup_rfkill (); fail_rfkill:
@@ -2278,7 +2288,8 @@ static void __exit dell_exit(void)touchpad_led_exit ();kbd_led_exit ();backlight_device_unregister (dell_backlight_device); -led_classdev_unregister (&micmute_led_cdev); +if (!has_privacy) +led_classdev_unregister (&micmute_led_cdev);dell_cleanup_rfkill ();if (platform_device) {platform_device_unregister (platform_device);
drivers/platform/x86/dell/dell-privacy-wmi.c new file +441 -0
441 lines not on this page · raw message
drivers/platform/x86/dell/dell-privacy-wmi.h new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Dell privacy notification driver +* +* Copyright (C) 2021 Dell Inc. All Rights Reserved. +*/ + +#ifndef _DELL_PRIVACY_WMI_H_ +#define _DELL_PRIVACY_WMI_H_ + +#if IS_ENABLED (CONFIG_DELL_PRIVACY ) +int dell_privacy_has_micmute (void ); +bool dell_privacy_present (void ); +bool dell_privacy_process_event (int type,int code,int status); +#else /* CONFIG_DELL_PRIVACY */ +static inline int dell_privacy_has_micmute (void ) +{ +return -ENODEV ; +} + +static inline int dell_privacy_present (void ) +{ +return -ENODEV ; +} + +static inline void dell_privacy_process_event (int type,int code,int status) +{} +#endif /* CONFIG_DELL_PRIVACY */ + +int dell_privacy_acpi_init (void ); +void dell_privacy_acpi_exit (void ); +#endif
drivers/platform/x86/dell/dell-wmi.c +12 -1
@@ -27,6 +27,7 @@#include <acpi/video.h> #include "dell-smbios.h" #include "dell-wmi-descriptor.h" +#include "dell-privacy-wmi.h" MODULE_AUTHOR ("Matthew Garrett <[email protected]>" );MODULE_AUTHOR ("Pali Rohár <[email protected]>" );
@@ -381,6 +382,7 @@ static void dell_wmi_notify(struct wmi_device *wdev,u16 *buffer_entry, *buffer_end;acpi_size buffer_size;int len, i; +int ret;if (obj->type !=ACPI_TYPE_BUFFER ) {pr_warn ("bad response type %x\n" , obj->type);
@@ -427,7 +429,6 @@ static void dell_wmi_notify(struct wmi_device *wdev,switch (buffer_entry[1 ]) {case 0x0000 :/* One key pressed or event occurred */ -case 0x0012 :/* Event with extended data occurred */ if (len >2 )dell_wmi_process_key (wdev, buffer_entry[1 ], buffer_entry[2 ]);
@@ -439,6 +440,16 @@ static void dell_wmi_notify(struct wmi_device *wdev,dell_wmi_process_key (wdev, buffer_entry[1 ], buffer_entry[i]);break ; +case 0x0012 : + ret =dell_privacy_present (); +if ((ret) && (len >2 )) { +dell_privacy_process_event (buffer_entry[1 ], + buffer_entry[3 ], buffer_entry[4 ]); + }else if (len >2 ) { +dell_wmi_process_key (wdev, buffer_entry[1 ], + buffer_entry[2 ]); + } +break ;default :/* Unknown event */ pr_info ("Unknown WMI event type 0x%x\n" , (int )buffer_entry[1 ]);
Signature · 1 line
2.25.1
Hi
2021. április 4., vasárnap 10:31 keltezéssel, Perry Yuan írta:
Quoted 89 lines
From: Perry Yuan <[email protected]>
add support for Dell privacy driver for the Dell units equipped hardware privacy design, which protect users privacy of audio and camera from hardware level. Once the audio or camera privacy mode activated, any applications will not get any audio or video stream when user pressed ctrl+F4 hotkey, audio privacy mode will be enabled, micmute led will be also changed accordingly
The micmute led is fully controlled by hardware & EC(embedded controller) and camera mute hotkey is Ctrl+F9. Currently design only emitsSW_CAMERA_LENS_COVERevent while the camera lens shutter will be changed by EC & HW(hardware) control*The flow is like this:
1) User presses key. HW does stuff with this key (timeout timer is started)
2) WMI event is emitted from BIOS to kernel
3) WMI event is received by dell-privacy
4)KEY_MICMUTEemitted from dell-privacy
5) Userland picks up key and modifies kcontrol for SW mute
6) Codec kernel driver catches and callsledtrig_audio_set, like this:ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led ? LED_ON :LED_OFF);7) If "LED" is set to on dell-privacy notifies EC, and timeout is cancelled, HW mic mute activated. If EC not notified, HW mic mute will also be activated when timeout used up, it is just later than active ack
Signed-off-by Perry Yuan <[email protected]>---
v5 -> v6:
* addressed feedback from Hans
* addressed feedback from Pierre
* optimize some debug format withdev_dbg()
* remove platform driver,combined privacy acpi driver into single wmi driver file
* optimize sysfs interface with string added to be more clearly reading v4 -> v5:
* addressed feedback from Randy Dunlap
* addressed feedback from Pierre-Louis Bossart
* rebase to latest 5.12 rc4 upstream kernel
* fix some space alignment problem
v3 -> v4:
* fix format forKconfig
* add sysfs document
* add flow comments to the privacy wmi/acpi driver
* addressed feedback from Barnabás Pőcze[Thanks very much]
* exportprivacy_validto make the global state simpler to query
* fix one issue which will block the dell-laptop driver to load when privacy driver invalid
* addressed feedback from Pierre-Louis Bossart,remove the EC ID match v2 -> v3:
* add sysfs attributes doc
v1 -> v2:
* query EC handle from EC driver directly.
* fix some code style.
* addKEY_ENDto keymap array.
* clean platform device when cleanup called
* use hexadecimal format for log print indev_dbg
* remove__set_bitfor the report keys from probe.
* fix keymap leak
* adderr_free_keymapindell_privacy_wmi_probe
* wmi driver will be unregistered ifprivacy_acpi_init()fails
* add sysfs attribute files for user space query.
* add leds micmute driver to privacy acpi
* add more design info the commit info
------ .../testing/sysfs-platform-dell-privacy-wmi | 55 +++ drivers/platform/x86/dell/Kconfig | 14 + drivers/platform/x86/dell/Makefile | 1 + drivers/platform/x86/dell/dell-laptop.c | 23 +- drivers/platform/x86/dell/dell-privacy-wmi.c | 441 ++++++++++++++++++ drivers/platform/x86/dell/dell-privacy-wmi.h | 32 ++ drivers/platform/x86/dell/dell-wmi.c | 13 +- 7 files changed, 572 insertions(+), 7 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi create mode 100644 drivers/platform/x86/dell/dell-privacy-wmi.c create mode 100644 drivers/platform/x86/dell/dell-privacy-wmi.hDocumentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +6
-0@@ -0,0 +1,55 @@ +What: /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/dell_privacy_supported_type +Date: Apr 2021 +KernelVersion: 5.13 +Contact: "[email protected]>" +Description: + Display which dell hardware level privacy devices are supported
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 16
Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +10
-0+ “Dell Privacy” is a set of HW, FW, and SW features to enhance + Dell’s commitment to platform privacy for MIC, Camera, and + ePrivacy screens. + The supported hardware privacy devices are: +Attributes: + Microphone Mute: + Identifies the local microphone can be muted by hardware, no applications + is available to capture system mic sound + + Camera Shutter:
^^^^^^^^^^^^^^^^
Spaces used instead of tabs.
Quoted 155 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +39
-0+ Identifies camera shutter controlled by hardware, which is a micromechanical + shutter assembly that is built onto the camera module to block capturing images + from outside the laptop + + supported: + The privacy device is supported by this system + + unsupported: + The privacy device is not supported on this system + + For example to check which privacy devices are supported: + + # cat /sys/bus/wmi/drivers/dell-privacy/6932965F-1671-4CEB-B988-D3AB0A901919/dell_privacy_supported_type + [Microphone Mute] [supported] + [Camera Shutter] [supported] + [ePrivacy Screen] [unsupport] + +What: /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/dell_privacy_current_state +Date: Apr 2021 +KernelVersion: 5.13 +Contact: "[email protected]>" +Description: + Allow user space to check current dell privacy device state. + Describes the Device State class exposed by BIOS which can be + consumed by various applications interested in knowing the Privacy + feature capabilities +Attributes: + muted: + Identifies the privacy device is turned off and cannot send stream to OS applications + + unmuted: + Identifies the privacy device is turned on ,audio or camera driver can get + stream from mic and camera module to OS applications + + For example to check all supported current privacy device states: + + # cat /sys/bus/wmi/drivers/dell-privacy/6932965F-1671-4CEB-B988-D3AB0A901919/dell_privacy_current_state + [Microphone] [unmuted] + [Camera Shutter] [unmuted]drivers/platform/x86/dell/Kconfig +14
-0@@ -204,4 +204,18 @@ config DELL_WMI_SYSMAN To compile this driver as a module, choose M here: the module will be called dell-wmi-sysman. +config DELL_PRIVACY + tristate "Dell Hardware Privacy Support" + depends on ACPI + depends on ACPI_WMI + depends on INPUT + depends on DELL_LAPTOP + depends on LEDS_TRIGGER_AUDIO + select DELL_WMI + help + This driver provides integration with the "Dell Hardware Privacy" feature + of Dell laptops. + + To compile this driver as a module, choose M here: the module will + be called dell_privacy. endif # X86_PLATFORM_DRIVERS_DELLdrivers/platform/x86/dell/Makefile +1
-0@@ -19,3 +19,4 @@ obj-$(CONFIG_DELL_WMI_AIO) += dell-wmi-aio.o obj-$(CONFIG_DELL_WMI_DESCRIPTOR) += dell-wmi-descriptor.o obj-$(CONFIG_DELL_WMI_LED) += dell-wmi-led.o obj-$(CONFIG_DELL_WMI_SYSMAN) += dell-wmi-sysman/ +obj-$(CONFIG_DELL_PRIVACY) += dell-privacy-wmi.odrivers/platform/x86/dell/dell-laptop.c +17
-6@@ -31,6 +31,8 @@#include "dell-rbtn.h" #include "dell-smbios.h" +#include "dell-privacy-wmi.h" +struct quirk_entry {bool touchpad_led;bool kbd_led_not_present;@@ -90,6 +92,7 @@ static struct rfkill *wifi_rfkill;static struct rfkill *bluetooth_rfkill;static struct rfkill *wwan_rfkill;static bool force_rfkill; +static bool has_privacy;module_param (force_rfkill, bool,0444 );MODULE_PARM_DESC (force_rfkill,"enable rfkill on non whitelisted models" );@@ -2206,10 +2209,16 @@ static int __init dell_init(void)if (dell_smbios_find_token (GLOBAL_MIC_MUTE_DISABLE ) &&dell_smbios_find_token (GLOBAL_MIC_MUTE_ENABLE )) { - micmute_led_cdev.brightness =ledtrig_audio_get (LED_AUDIO_MICMUTE ); - ret =led_classdev_register (&platform_device->dev, &micmute_led_cdev); -if (ret <0 ) - goto fail_led; +if (dell_privacy_has_micmute ()) + has_privacy = true; +else + has_privacy = false; +if (!has_privacy) { + micmute_led_cdev.brightness =ledtrig_audio_get (LED_AUDIO_MICMUTE ); + ret =led_classdev_register (&platform_device->dev, &micmute_led_cdev); +if (ret <0 ) + goto fail_led; + } }if (acpi_video_get_backlight_type () != acpi_backlight_vendor)@@ -2257,7 +2266,8 @@ static int __init dell_init(void) fail_get_brightness:backlight_device_unregister (dell_backlight_device); fail_backlight: -led_classdev_unregister (&micmute_led_cdev); +if (!has_privacy) +led_classdev_unregister (&micmute_led_cdev); fail_led:dell_cleanup_rfkill (); fail_rfkill:@@ -2278,7 +2288,8 @@ static void __exit dell_exit(void)touchpad_led_exit ();kbd_led_exit ();backlight_device_unregister (dell_backlight_device); -led_classdev_unregister (&micmute_led_cdev); +if (!has_privacy) +led_classdev_unregister (&micmute_led_cdev);dell_cleanup_rfkill ();if (platform_device) {platform_device_unregister (platform_device);drivers/platform/x86/dell/dell-privacy-wmi.c new file +16
-0@@ -0,0 +1,441 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Dell privacy notification driver +* +* Copyright (C) 2021 Dell Inc. All Rights Reserved. +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/acpi.h> +#include <linux/bitops.h> +#include <linux/input.h> +#include <linux/input/sparse-keymap.h> +#include <linux/list.h> +#include <linux/leds.h> +#include <linux/module.h>
drivers/platform/x86/dell/dell-privacy-wmi.c line 26
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+#include <linux/wmi.h> + +#include "dell-privacy-wmi.h" + +#define DELL_PRIVACY_GUID "6932965F-1671-4CEB-B988-D3AB0A901919" +#define MICROPHONE_STATUS BIT(0) +#define CAMERA_STATUS BIT(1) +#define DELL_PRIVACY_AUDIO_EVENT 0x1 +#define DELL_PRIVACY_CAMERA_EVENT 0x2 +#define cdev_to_led (c) container_of(c, struct privacy_wmi_data, cdev)
This name is confusing in my opinion. Something like led_to_priv could be clearer.
Quoted 77 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +77
-0+ +/* +* The wmi_list is used to store the privacy_priv struct with mutex protecting +*/ +static LIST_HEAD (wmi_list); +static DEFINE_MUTEX (list_mutex); + +struct privacy_wmi_data { +struct input_dev *input_dev; +struct wmi_device *wdev; +struct list_head list; +struct led_classdev cdev; +u32 features_present; +u32 last_status; +}; + +/* DELL Privacy Type */ +enum dell_hardware_privacy_type { +DELL_PRIVACY_TYPE_AUDIO =0 , +DELL_PRIVACY_TYPE_CAMERA , +DELL_PRIVACY_TYPE_SCREEN , +DELL_PRIVACY_TYPE_MAX , +}; + +static const char *const privacy_types[DELL_PRIVACY_TYPE_MAX ] = { + [DELL_PRIVACY_TYPE_AUDIO ] ="Microphone" , + [DELL_PRIVACY_TYPE_CAMERA ] ="Camera Shutter" , + [DELL_PRIVACY_TYPE_SCREEN ] ="ePrivacy Screen" , +}; + +/* +* Keymap for WMI privacy events of type 0x0012 +*/ +static const struct key_entry dell_wmi_keymap_type_0012[] = { +/* privacy mic mute */ + {KE_KEY ,0x0001 , {KEY_MICMUTE } }, +/* privacy camera mute */ + {KE_SW ,0x0002 , {SW_CAMERA_LENS_COVER } }, + {KE_END ,0 }, +}; + +/* +* global privacy state for other modules to query if the privacy driver loaded successfully +* or no privacy WMI device was detected at initial probe phase +*/ +bool dell_privacy_present (void ) +{ +struct privacy_wmi_data *priv; + +mutex_lock (&list_mutex); + priv =list_first_entry_or_null (&wmi_list, + struct privacy_wmi_data, + list); +mutex_unlock (&list_mutex); + +return priv; +} +EXPORT_SYMBOL_GPL (dell_privacy_present); + +/* +* Allow other modules to check current dell privacy mic mute state +*/ +int dell_privacy_has_micmute (void ) +{ +struct privacy_wmi_data *priv; +int ret; + +mutex_lock (&list_mutex); + priv =list_first_entry_or_null (&wmi_list, + struct privacy_wmi_data, + list); +/* +* There is no privacy device node yet, so we need to wait +* until the privacy driver has created software node for the micmute device. +* This function will return -EPROBE_DEFER until the privacy device is registered. +*/ +if (!priv) {
drivers/platform/x86/dell/dell-privacy-wmi.c line 113
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ ret = -EPROBE_DEFER ; + goto out; + } + ret = priv->features_present &MICROPHONE_STATUS ; +if (!ret) { +dev_err (&priv->wdev->dev,"privacy mic mute feature is not supported: %d\n" , ret); + ret = -ENODEV ; + goto out; + } +dev_err (&priv->wdev->dev,"privacy mic mute feature is supported: %d\n" , ret);
I think this could be dev_info(), but definitely not dev_err(). Although I'd personally move the logging from here to the probe function if you want to log which features are available. ret is necessarily 1 here, so I don't think printing it provides additional information.
Quoted 25 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +25
-0+ +out: +mutex_unlock (&list_mutex); +return ret; +} +EXPORT_SYMBOL_GPL (dell_privacy_has_micmute); + +/* +* The flow of privacy event: +* 1) User presses key. HW does stuff with this key (timeout is started) +* 2) WMI event is emitted from BIOS +* 3) WMI event is received by dell-privacy +* 4) KEY_MICMUTE emitted from dell-privacy +* 5) Userland picks up key and modifies kcontrol for SW mute +* 6) Codec kernel driver catches and calls ledtrig_audio_set defined by +* dell-privacy-acpi driver. Codec driver will call like this to switch micmute led state. +* ledtrig_audio_set(LED_AUDIO_MICMUTE, micmute_led ? LED_ON :LED_OFF); +* 7) If "LED" is set to on dell-privacy notifies EC,and timeout is cancelled, +* HW mic mute activated. +*/ +bool dell_privacy_process_event (int type,int code,int status) +{ +struct privacy_wmi_data *priv; +const struct key_entry *key; +bool ret = false;
drivers/platform/x86/dell/dell-privacy-wmi.c line 148
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ +mutex_lock (&list_mutex); + priv =list_first_entry_or_null (&wmi_list, + struct privacy_wmi_data, + list); +if (!priv) { +dev_err (&priv->wdev->dev,"priv data is NULL\n" ); + goto error; + } +
I think the rest of the function could be replaced with:
ret = sparse_keymap_report_event(priv->input_dev, DELL_SCAN_CODE(type, code), 1, true)
if (ret)
priv->last_status = status;error:
[...]
(see later a comment for the definition of DELL_SCAN_CODE())
Quoted 7 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +7
-0+ key =sparse_keymap_entry_from_scancode (priv->input_dev, (type <<16 ) | code); +if (!key) { +dev_warn (&priv->wdev->dev,"Unknown key with type 0x%04x and code 0x%04x pressed\n" , + type, code); + goto error; + } +dev_dbg (&priv->wdev->dev,"Key with type 0x%04x and code 0x%04x pressed\n" , type, code);
drivers/platform/x86/dell/dell-privacy-wmi.c line 165
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ +switch (code) { +case DELL_PRIVACY_AUDIO_EVENT :/* Mic mute */ +case DELL_PRIVACY_CAMERA_EVENT :/* Camera mute */ + priv->last_status = status; +sparse_keymap_report_entry (priv->input_dev, key,1 , true); + ret = true; +break ; +default : +dev_dbg (&priv->wdev->dev,"unknown event type 0x%04x 0x%04x" , type, code);
The capitalization is inconsistent. Please either make all messages lowercase or make them all start with an uppercase letter. (And a newline character is missing.)
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ } + +error: +mutex_unlock (&list_mutex); +return ret; +} +EXPORT_SYMBOL_GPL (dell_privacy_process_event); + +static ssize_t dell_privacy_supported_type_show(struct device *dev, + struct device_attribute *attr,
drivers/platform/x86/dell/dell-privacy-wmi.c line 185
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ char *buf) +{ +enum dell_hardware_privacy_type type; +struct privacy_wmi_data *priv =dev_get_drvdata (dev); +char *s = buf; +u32 privacy_list; + + privacy_list = priv->features_present; +for (type =DELL_PRIVACY_TYPE_AUDIO ; type <DELL_PRIVACY_TYPE_MAX ; type++) { +if (privacy_types[type]) {
Is this check necessary?
drivers/platform/x86/dell/dell-privacy-wmi.c line 189
Quoted 4 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +4
-0+if (privacy_list &BIT (type)) + s +=sprintf (s,"[%s] [supported]\n" , privacy_types[type]); +else + s +=sprintf (s,"[%s] [unsupport]\n" , privacy_types[type]);
You can use sysfs_emit_at() here.
drivers/platform/x86/dell/dell-privacy-wmi.c line 195
Quoted 6 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +6
-0+ } + } + +if (s != buf) +/* convert the last space to a newline */ + *(s-1 ) ='\n' ;
I believe this is not needed?
Quoted 9 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +9
-0+return (s - buf); +} + +static ssize_t dell_privacy_current_state_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (dev); +enum dell_hardware_privacy_type type;
drivers/platform/x86/dell/dell-privacy-wmi.c line 214
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+u32 privacy_state = priv->last_status; +u32 privacy_supported = priv->features_present; +char *s = buf; + +for (type =DELL_PRIVACY_TYPE_AUDIO ; type <DELL_PRIVACY_TYPE_MAX ; type++) { +if (privacy_supported &BIT (type)) { +if (privacy_state &BIT (type)) + s +=sprintf (s,"[%s] [unmuted]\n" , privacy_types[type]); +else + s +=sprintf (s,"[%s] [muted]\n" , privacy_types[type]);
sysfs_emit_at
drivers/platform/x86/dell/dell-privacy-wmi.c line 195
Quoted 6 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +6
-0+ } + } + +if (s != buf) +/* convert the last space to a newline */ + *(s-1 ) ='\n' ;
not needed?
Quoted 15 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +15
-0+return (s - buf); +} + +static DEVICE_ATTR_RO (dell_privacy_supported_type); +static DEVICE_ATTR_RO (dell_privacy_current_state); + +static struct attribute *privacy_attributes[] = { + &dev_attr_dell_privacy_supported_type.attr, + &dev_attr_dell_privacy_current_state.attr, +NULL , +}; + +static const struct attribute_group privacy_attribute_group = { + .attrs = privacy_attributes +};
drivers/platform/x86/dell/dell-privacy-wmi.c line 245
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ +/* +* Describes the Device State class exposed by BIOS which can be consumed by +* various applications interested in knowing the Privacy feature capabilities. +* class DeviceState +* { +* [key, read] string InstanceName; +* [read] boolean ReadOnly; +* [WmiDataId(1), read] uint32 DevicesSupported; +* 0 – None, 0x1 – Microphone, 0x2 – Camera, 0x4 -ePrivacy Screen
^ ^ ^ ^ ^^
Please use a single type of hyphen/dash consistently. One space is enough.
drivers/platform/x86/dell/dell-privacy-wmi.c line 247
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +2
-0+* [WmiDataId(2), read] uint32 CurrentState; +* 0:Off; 1:On. Bit0 – Microphone, Bit1 – Camera, Bit2 - ePrivacyScreen
^ ^ ^
Same here.
drivers/platform/x86/dell/dell-privacy-wmi.c line 258
Quoted 11 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +11
-0+* }; +*/ +static int get_current_status (struct wmi_device *wdev) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (&wdev->dev); +union acpi_object *obj_present; +u32 *buffer; +int ret =0 ; + +if (!priv) { +pr_err ("dell privacy priv is NULL\n" );
dev_err?
drivers/platform/x86/dell/dell-privacy-wmi.c line 266
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+return -EINVAL ; + } +/* check privacy support features and device states */ + obj_present =wmidev_block_query (wdev,0 ); +if (!obj_present) { +dev_err (&wdev->dev,"failed to read Binary MOF\n" ); + ret = -EIO ; +return ret;
return -EIO ?
Quoted 9 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +9
-0+ } + +if (obj_present->type !=ACPI_TYPE_BUFFER ) { +dev_err (&wdev->dev,"Binary MOF is not a buffer!\n" ); + ret = -EIO ; + goto obj_free; + } +/* Although it's not technically a failure, this would lead to +* unexpected behavior
drivers/platform/x86/dell/dell-privacy-wmi.c line 285
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+*/ +if (obj_present->buffer.length !=8 ) { +dev_err (&wdev->dev,"Dell privacy buffer has unexpected length (%d)!\n" , + obj_present->buffer.length); + ret = -EINVAL ; + goto obj_free; + } + buffer = (u32 *)obj_present->buffer.pointer; + priv->features_present = buffer[0 ]; + priv->last_status = buffer[1 ];
It's a minor thing, but I still think it'd more explicit and somewhat better to use get_unaligned_le32() (or get_unaligned_cpu32()).
Quoted 49 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +49
-0+ +obj_free: +kfree (obj_present); +return ret; +} + +static int dell_privacy_micmute_led_set (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +struct privacy_wmi_data *priv =cdev_to_led (led_cdev); +static char *acpi_method = (char *)"ECAK" ; +acpi_status status; +acpi_handle handle; + + handle =ec_get_handle (); +if (!handle) +return -EIO ; + +if (!acpi_has_method (handle, acpi_method)) +return -EIO ; + + status =acpi_evaluate_object (handle, acpi_method,NULL ,NULL ); +if (ACPI_FAILURE (status)) { +dev_err (&priv->wdev->dev,"Error setting privacy EC ack value: %s\n" , +acpi_format_exception (status)); +return -EIO ; + } + +return 0 ; +} + +/* +* Pressing the mute key activates a time delayed circuit to physically cut +* off the mute. The LED is in the same circuit, so it reflects the true +* state of the HW mute. The reason for the EC "ack" is so that software +* can first invoke a SW mute before the HW circuit is cut off. Without SW +* cutting this off first does not affect the time delayed muting or status +* of the LED but there is a possibility of a "popping" noise. +* +* If the EC receives the SW ack, the circuit will be activated before the +* delay completed. +* +* Exposing as an LED device allows the codec drivers notification path to +* EC ACK to work +*/ +static int dell_privacy_leds_setup (struct device *dev) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (dev); +int ret;
drivers/platform/x86/dell/dell-privacy-wmi.c line 344
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ + priv->cdev.name ="dell-privacy::micmute" ; + priv->cdev.max_brightness =1 ; + priv->cdev.brightness_set_blocking = dell_privacy_micmute_led_set; + priv->cdev.default_trigger ="audio-micmute" ; + priv->cdev.brightness =ledtrig_audio_get (LED_AUDIO_MICMUTE ); + ret =devm_led_classdev_register (dev, &priv->cdev); +if (ret) +return ret; +return 0 ;
You can replace the last four lines with:
return devm_led_classdev_register(...);
drivers/platform/x86/dell/dell-privacy-wmi.c line 355
Quoted 11 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +11
-0+} + +static int dell_privacy_wmi_probe (struct wmi_device *wdev,const void *context) +{ +struct privacy_wmi_data *priv; +struct key_entry *keymap; +int ret, i; + + ret =wmi_has_guid (DELL_PRIVACY_GUID ); +if (!ret) +pr_debug ("Unable to detect available Dell privacy devices: %d\n" , ret);
When this branch is taken, ret is necessarily zero, so I don't think printing it provides useful information.
And I believe this wmi_has_guid() check is unnecessary since the probe method would not be called if the device didn't have such WMI guid if I'm not mistaken.
Quoted 15 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +15
-0+ + priv =devm_kzalloc (&wdev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + +dev_set_drvdata (&wdev->dev, priv); + priv->wdev = wdev; +/* create evdev passing interface */ + priv->input_dev =devm_input_allocate_device (&wdev->dev); +if (!priv->input_dev) +return -ENOMEM ; + +/* remap the wmi keymap event to new keymap */ + keymap =kcalloc (ARRAY_SIZE (dell_wmi_keymap_type_0012), +sizeof (struct key_entry ),GFP_KERNEL );
drivers/platform/x86/dell/dell-privacy-wmi.c line 380
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+if (!keymap) +return -ENOMEM ; + +/* remap the keymap code with Dell privacy key type 0x12 as prefix +* KEY_MICMUTE scancode will be reported as 0x120001 +*/ +for (i =0 ; i <ARRAY_SIZE (dell_wmi_keymap_type_0012); i++) { + keymap[i] = dell_wmi_keymap_type_0012[i]; + keymap[i].code |= (0x0012 <<16 ); + }
I still don't see the need for allocating and copying the keymap. Wouldn't the following be sufficient?
#define DELL_SCAN_CODE(type, code) ((type) << 16 | (code))
static const struct key_entry dell_wmi_keymap_type_0012[] = {
{ KE_KEY, DELL_SCAN_CODE(0x0012, 0x0001), { KEY_MICMUTE } },
{ KE_SW, DELL_SCAN_CODE(0x0012, 0x0002), { SW_CAMERA_LENS_COVER } },
{ KE_END, 0},
};Other Dell drivers potentially merge multiple keymaps, so dynamically allocating the key_entry array is justified. Here I see no such need. Can you explain why this copying is done?
drivers/platform/x86/dell/dell-privacy-wmi.c line 383
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +3
-0+ ret =sparse_keymap_setup (priv->input_dev, keymap,NULL ); +if (ret) +return ret;
keymap is leaked if this or any of the later early-returns are taken.
Quoted 75 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +58
-0+ + priv->input_dev->dev.parent = &wdev->dev; + priv->input_dev->name ="Dell Privacy Driver" ; + priv->input_dev->id.bustype =BUS_HOST ; + + ret =input_register_device (priv->input_dev); +if (ret) +return ret; + + ret =get_current_status (priv->wdev); +if (ret) +return ret; + + ret =devm_device_add_group (&wdev->dev, &privacy_attribute_group); +if (ret) +return ret; + + ret =dell_privacy_leds_setup (&priv->wdev->dev); +if (ret) +return ret; + +mutex_lock (&list_mutex); +list_add_tail (&priv->list, &wmi_list); +mutex_unlock (&list_mutex); +kfree (keymap); +return 0 ; +} + +static int dell_privacy_wmi_remove (struct wmi_device *wdev) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (&wdev->dev); + +mutex_lock (&list_mutex); +list_del (&priv->list); +mutex_unlock (&list_mutex); +return 0 ; +} + +static const struct wmi_device_id dell_wmi_privacy_wmi_id_table[] = { + { .guid_string =DELL_PRIVACY_GUID }, + { }, +}; + +static struct wmi_driver dell_privacy_wmi_driver = { + .driver = { + .name ="dell-privacy" , + }, + .probe = dell_privacy_wmi_probe, + .remove = dell_privacy_wmi_remove, + .id_table = dell_wmi_privacy_wmi_id_table, +}; + +module_wmi_driver (dell_privacy_wmi_driver); + +MODULE_DEVICE_TABLE (wmi, dell_wmi_privacy_wmi_id_table); +MODULE_AUTHOR ("Perry Yuan <[email protected]>" ); +MODULE_DESCRIPTION ("Dell Privacy WMI Driver" ); +MODULE_LICENSE ("GPL" );drivers/platform/x86/dell/dell-privacy-wmi.h new file +11
-0@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Dell privacy notification driver +* +* Copyright (C) 2021 Dell Inc. All Rights Reserved. +*/ + +#ifndef _DELL_PRIVACY_WMI_H_ +#define _DELL_PRIVACY_WMI_H_ + +#if IS_ENABLED (CONFIG_DELL_PRIVACY )
drivers/platform/x86/dell/dell-privacy-wmi.h line 21
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +10
-0+int dell_privacy_has_micmute (void ); +bool dell_privacy_present (void ); +bool dell_privacy_process_event (int type,int code,int status); +#else /* CONFIG_DELL_PRIVACY */ +static inline int dell_privacy_has_micmute (void ) +{ +return -ENODEV ; +} + +static inline int dell_privacy_present (void )
^^^
It's declared with bool return type a couple lines above.
drivers/platform/x86/dell/dell-privacy-wmi.h line 26
Quoted 5 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +5
-0+{ +return -ENODEV ; +} + +static inline void dell_privacy_process_event (int type,int code,int status)
^^^^
It's declared with bool return type a couple lines above.
drivers/platform/x86/dell/dell-privacy-wmi.h line 31
Quoted 5 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +5
-0+{} +#endif /* CONFIG_DELL_PRIVACY */ + +int dell_privacy_acpi_init (void ); +void dell_privacy_acpi_exit (void );
These two don't seem to be referenced anywhere?
Quoted 30 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +1
-0+#endif drivers/platform/x86/dell/dell-wmi.c +2
-1@@ -27,6 +27,7 @@#include <acpi/video.h> #include "dell-smbios.h" #include "dell-wmi-descriptor.h" +#include "dell-privacy-wmi.h" MODULE_AUTHOR ("Matthew Garrett <[email protected]>" );MODULE_AUTHOR ("Pali Rohár <[email protected]>" );@@ -381,6 +382,7 @@ static void dell_wmi_notify(struct wmi_device *wdev,u16 *buffer_entry, *buffer_end;acpi_size buffer_size;int len, i; +int ret;if (obj->type !=ACPI_TYPE_BUFFER ) {pr_warn ("bad response type %x\n" , obj->type);@@ -427,7 +429,6 @@ static void dell_wmi_notify(struct wmi_device *wdev,switch (buffer_entry[1 ]) {case 0x0000 :/* One key pressed or event occurred */ -case 0x0012 :/* Event with extended data occurred */ if (len >2 )dell_wmi_process_key (wdev, buffer_entry[1 ], buffer_entry[2 ]);
drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device *wdev, · line 445
Quoted 6 lines
drivers/platform/x86/dell/dell-wmi.c +3
-0@@ -439,6 +440,16 @@ static void dell_wmi_notify(struct wmi_device *wdev,dell_wmi_process_key (wdev, buffer_entry[1 ], buffer_entry[i]);break ; +case 0x0012 : + ret =dell_privacy_present (); +if ((ret) && (len >2 )) {
Is the len > 2 check correct?
Moreover, I personally don't see any reason to use a new variable here (ret).
If you incorporate the dell_privacy_present() check into dell_privacy_process_event(), then even
if (len > ?? && dell_privacy_process_event(...))
/* nothing */ ;
else if (len > 2)
dell_wmi_process_key(...);would work as Hans has already pointed it out. And there'd be no need for dell_privacy_present() anymore.
Quoted 11 lines
drivers/platform/x86/dell/dell-wmi.c +7
-1+dell_privacy_process_event (buffer_entry[1 ], + buffer_entry[3 ], buffer_entry[4 ]); + }else if (len >2 ) { +dell_wmi_process_key (wdev, buffer_entry[1 ], + buffer_entry[2 ]); + } +break ;default :/* Unknown event */ pr_info ("Unknown WMI event type 0x%x\n" , (int )buffer_entry[1 ]); --
Quoted 2 lines
2.25.1
Regards,
Barnabás Pőcze
Quoted 7 lines
I think this could be
dev_info(), but definitely notdev_err(). Although I'd
personally move the logging from here to the probe function if you want to log which features are available.retis necessarily 1 here, so I don't think printing it
provides additional information.
To the layman I would say dev_info is too noisy actually. I think debugging (dev_dbg) would be just fine. If there is a function not working, adding dynamic debugging on kernel command line of modprobe line will be plenty sufficient to get this information.
Quoted 572 lines
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +6
-0+ +out: +mutex_unlock (&list_mutex); +return ret; +} +EXPORT_SYMBOL_GPL (dell_privacy_has_micmute);drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ +/* +* The flow of privacy event: +* 1) User presses key. HW does stuff with this key (timeout is started) +* 2) WMI event is emitted from BIOS +* 3) WMI event is received by dell-privacy +* 4) KEY_MICMUTE emitted from dell-privacy +* 5) Userland picks up key and modifies kcontrol for SW mute +* 6) Codec kernel driver catches and calls ledtrig_audio_set defined by +* dell-privacy-acpi driver. Codec driver will call like this to switch micmute led state.
Quoted 2 lines
+ *
ledtrig_audio_set(LED_AUDIO_MICMUTE, micmute_led ? LED_ON :LED_OFF);
+ * 7) If "LED" is set to on dell-privacy notifies EC,and timeout iscancelled,
Quoted 7 lines
+ * HW mic mute activated.
+ */drivers/platform/x86/dell/dell-privacy-wmi.c new file +5
-0+bool dell_privacy_process_event (int type,int code,int status) +{ +struct privacy_wmi_data *priv; +const struct key_entry *key; +bool ret = false;drivers/platform/x86/dell/dell-privacy-wmi.c line 148
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ +mutex_lock (&list_mutex); + priv =list_first_entry_or_null (&wmi_list, + struct privacy_wmi_data, + list); +if (!priv) { +dev_err (&priv->wdev->dev,"priv data is NULL\n" ); + goto error; + } +I think the rest of the function could be replaced with:
ret = sparse_keymap_report_event(priv->input_dev, DELL_SCAN_CODE(type,
code), 1, true)if (ret) priv->last_status = status;error:
[...](see later a comment for the definition of
DELL_SCAN_CODE())Review
Quoted 1 line
(quoted diff) +1
-0+ key = sparse_keymap_entry_from_scancode(priv->input_dev, (type << 16) |code);
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!key) { + dev_warn(&priv->wdev->dev, "Unknown key with type 0x%04x and code0x%04x pressed\n",
drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 4 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +4
-0+ type, code); + goto error; + } + dev_dbg(&priv->wdev->dev, "Key with type 0x%04x and code 0x%04xpressed\n", type, code);
drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ +switch (code) { +case DELL_PRIVACY_AUDIO_EVENT :/* Mic mute */ +case DELL_PRIVACY_CAMERA_EVENT :/* Camera mute */ + priv->last_status = status; +sparse_keymap_report_entry (priv->input_dev, key,1 , true); + ret = true; +break ; +default : + dev_dbg(&priv->wdev->dev, "unknown event type 0x%04x 0x%04x", type,code);
The capitalization is inconsistent. Please either make all messages lowercase or
make them all start with an uppercase letter. (And a newline character is missing.)Quoted 9 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +9
-0+ } + +error: +mutex_unlock (&list_mutex); +return ret; +} +EXPORT_SYMBOL_GPL (dell_privacy_process_event); + +static ssize_t dell_privacy_supported_type_show(struct device *dev,drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+struct device_attribute *attr, + char *buf) +{ + enum dell_hardware_privacy_type type; +struct privacy_wmi_data *priv =dev_get_drvdata (dev); +char *s = buf; +u32 privacy_list; + + privacy_list = priv->features_present; + for (type = DELL_PRIVACY_TYPE_AUDIO; type < DELL_PRIVACY_TYPE_MAX;type++) {
drivers/platform/x86/dell/dell-privacy-wmi.c line 185
Quoted 1 line
drivers/platform/x86/dell/dell-privacy-wmi.c new file +1
-0+if (privacy_types[type]) {Is this check necessary?
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (privacy_list & BIT(type)) + s += sprintf(s, "[%s] [supported]\n",privacy_types[type]);
Review
Quoted 2 lines
(quoted diff) +2
-0+ else + s += sprintf(s, "[%s] [unsupport]\n",privacy_types[type]);
You can use
sysfs_emit_at()here.drivers/platform/x86/dell/dell-privacy-wmi.c line 195
Quoted 6 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +6
-0+ } + } + +if (s != buf) +/* convert the last space to a newline */ + *(s-1 ) ='\n' ;I believe this is not needed?
Quoted 4 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +4
-0+return (s - buf); +} + +static ssize_t dell_privacy_current_state_show(struct device *dev,drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+struct device_attribute *attr, + char *buf) +{ + struct privacy_wmi_data *priv = dev_get_drvdata(dev); +enum dell_hardware_privacy_type type; +u32 privacy_state = priv->last_status; +u32 privacy_supported = priv->features_present; +char *s = buf; + + for (type = DELL_PRIVACY_TYPE_AUDIO; type < DELL_PRIVACY_TYPE_MAX;type++) {
drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +3
-0+if (privacy_supported &BIT (type)) { +if (privacy_state &BIT (type)) + s += sprintf(s, "[%s] [unmuted]\n",privacy_types[type]);
Review
Quoted 2 lines
(quoted diff) +2
-0+ else + s += sprintf(s, "[%s] [muted]\n", privacy_types[type]);
sysfs_emit_atdrivers/platform/x86/dell/dell-privacy-wmi.c line 195
Quoted 6 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +6
-0+ } + } + +if (s != buf) +/* convert the last space to a newline */ + *(s-1 ) ='\n' ;not needed?
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+return (s - buf); +} + +static DEVICE_ATTR_RO (dell_privacy_supported_type); +static DEVICE_ATTR_RO (dell_privacy_current_state); + +static struct attribute *privacy_attributes[] = { + &dev_attr_dell_privacy_supported_type.attr,drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ &dev_attr_dell_privacy_current_state.attr, + NULL, +}; + +static const struct attribute_group privacy_attribute_group = { + .attrs = privacy_attributes +}; + +/* +* Describes the Device State class exposed by BIOS which can be consumed by
Quoted 1 line
+ * various applications interested in knowing the Privacy feature
capabilities.
Quoted 6 lines
+ * class DeviceState
+ * {+ * [key, read] string InstanceName; + * [read] boolean ReadOnly; + * [WmiDataId(1), read] uint32 DevicesSupported;+ * 0 – None,
0x1– Microphone,0x2– Camera,0x4-ePrivacy Screen^ ^ ^ ^ ^^
Please use a single type of hyphen/dash consistently. One space is enough.Quoted 2 lines
+ * [WmiDataId(2), read] uint32 CurrentState;
+ * 0:Off; 1:On. Bit0 – Microphone, Bit1 – Camera, Bit2 - ePrivacyScreen^ ^ ^
Same here.drivers/platform/x86/dell/dell-privacy-wmi.c line 258
Quoted 11 lines
+ * };
+ */drivers/platform/x86/dell/dell-privacy-wmi.c new file +9
-0+static int get_current_status (struct wmi_device *wdev) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (&wdev->dev); +union acpi_object *obj_present; +u32 *buffer; +int ret =0 ; + +if (!priv) { +pr_err ("dell privacy priv is NULL\n" );
dev_err?drivers/platform/x86/dell/dell-privacy-wmi.c line 266
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+return -EINVAL ; + } +/* check privacy support features and device states */ + obj_present =wmidev_block_query (wdev,0 ); +if (!obj_present) { +dev_err (&wdev->dev,"failed to read Binary MOF\n" ); + ret = -EIO ; +return ret;return
-EIO?drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 12 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +12
-0+ } + +if (obj_present->type !=ACPI_TYPE_BUFFER ) { +dev_err (&wdev->dev,"Binary MOF is not a buffer!\n" ); + ret = -EIO ; + goto obj_free; + } +/* Although it's not technically a failure, this would lead to +* unexpected behavior +*/ +if (obj_present->buffer.length !=8 ) { + dev_err(&wdev->dev, "Dell privacy buffer has unexpected length(%d)!\n",
drivers/platform/x86/dell/dell-privacy-wmi.c line 285
Quoted 7 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +7
-0+ obj_present->buffer.length); + ret = -EINVAL ; + goto obj_free; + } + buffer = (u32 *)obj_present->buffer.pointer; + priv->features_present = buffer[0 ]; + priv->last_status = buffer[1 ];It's a minor thing, but I still think it'd more explicit and somewhat better to
useget_unaligned_le32()(orget_unaligned_cpu32()).Quoted 14 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +14
-0+ +obj_free: +kfree (obj_present); +return ret; +} + +static int dell_privacy_micmute_led_set (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +struct privacy_wmi_data *priv =cdev_to_led (led_cdev); +static char *acpi_method = (char *)"ECAK" ; +acpi_status status; +acpi_handle handle; +drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ handle =ec_get_handle (); +if (!handle) +return -EIO ; + +if (!acpi_has_method (handle, acpi_method)) +return -EIO ; + + status =acpi_evaluate_object (handle, acpi_method,NULL ,NULL ); +if (ACPI_FAILURE (status)) { + dev_err(&priv->wdev->dev, "Error setting privacy EC ack value:%s\n",
Quoted 25 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +25
-0+ acpi_format_exception(status)); +return -EIO ; + } + +return 0 ; +} + +/* +* Pressing the mute key activates a time delayed circuit to physically cut +* off the mute. The LED is in the same circuit, so it reflects the true +* state of the HW mute. The reason for the EC "ack" is so that software +* can first invoke a SW mute before the HW circuit is cut off. Without SW +* cutting this off first does not affect the time delayed muting or status +* of the LED but there is a possibility of a "popping" noise. +* +* If the EC receives the SW ack, the circuit will be activated before the +* delay completed. +* +* Exposing as an LED device allows the codec drivers notification path to +* EC ACK to work +*/ +static int dell_privacy_leds_setup (struct device *dev) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (dev); +int ret;drivers/platform/x86/dell/dell-privacy-wmi.c line 344
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ + priv->cdev.name ="dell-privacy::micmute" ; + priv->cdev.max_brightness =1 ; + priv->cdev.brightness_set_blocking = dell_privacy_micmute_led_set; + priv->cdev.default_trigger ="audio-micmute" ; + priv->cdev.brightness =ledtrig_audio_get (LED_AUDIO_MICMUTE ); + ret =devm_led_classdev_register (dev, &priv->cdev); +if (ret) +return ret; +return 0 ;You can replace the last four lines with:
return devm_led_classdev_register(...);drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +3
-0+} + +static int dell_privacy_wmi_probe(struct wmi_device *wdev, const void*context)
drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+{ +struct privacy_wmi_data *priv; +struct key_entry *keymap; +int ret, i; + + ret =wmi_has_guid (DELL_PRIVACY_GUID ); +if (!ret) + pr_debug("Unable to detect available Dell privacy devices: %d\n",ret);
When this branch is taken,
retis necessarily zero, so I don't think printing it
provides useful information.And I believe this
wmi_has_guid()check is unnecessary since the probe method
would not be called if the device didn't have such WMI guid if I'm not mistaken.Quoted 15 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +15
-0+ + priv =devm_kzalloc (&wdev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + +dev_set_drvdata (&wdev->dev, priv); + priv->wdev = wdev; +/* create evdev passing interface */ + priv->input_dev =devm_input_allocate_device (&wdev->dev); +if (!priv->input_dev) +return -ENOMEM ; + +/* remap the wmi keymap event to new keymap */ + keymap =kcalloc (ARRAY_SIZE (dell_wmi_keymap_type_0012), +sizeof (struct key_entry ),GFP_KERNEL );drivers/platform/x86/dell/dell-privacy-wmi.c line 380
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+if (!keymap) +return -ENOMEM ; + +/* remap the keymap code with Dell privacy key type 0x12 as prefix +* KEY_MICMUTE scancode will be reported as 0x120001 +*/ +for (i =0 ; i <ARRAY_SIZE (dell_wmi_keymap_type_0012); i++) { + keymap[i] = dell_wmi_keymap_type_0012[i]; + keymap[i].code |= (0x0012 <<16 ); + }I still don't see the need for allocating and copying the keymap. Wouldn't the following be sufficient?
#define DELL_SCAN_CODE(type, code) ((type) << 16 | (code)) static const struct key_entry dell_wmi_keymap_type_0012[] = { { KE_KEY, DELL_SCAN_CODE(0x0012, 0x0001), { KEY_MICMUTE } }, { KE_SW, DELL_SCAN_CODE(0x0012, 0x0002), { SW_CAMERA_LENS_COVER } }, { KE_END, 0}, };Other Dell drivers potentially merge multiple keymaps, so dynamically allocating
thekey_entryarray is justified. Here I see no such need. Can you explain why this copying is done?drivers/platform/x86/dell/dell-privacy-wmi.c line 383
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +3
-0+ ret =sparse_keymap_setup (priv->input_dev, keymap,NULL ); +if (ret) +return ret;
keymapis leaked if this or any of the later early-returns are taken.Review
Quoted 59 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +58
-0+ + priv->input_dev->dev.parent = &wdev->dev; + priv->input_dev->name ="Dell Privacy Driver" ; + priv->input_dev->id.bustype =BUS_HOST ; + + ret =input_register_device (priv->input_dev); +if (ret) +return ret; + + ret =get_current_status (priv->wdev); +if (ret) +return ret; + + ret =devm_device_add_group (&wdev->dev, &privacy_attribute_group); +if (ret) +return ret; + + ret =dell_privacy_leds_setup (&priv->wdev->dev); +if (ret) +return ret; + +mutex_lock (&list_mutex); +list_add_tail (&priv->list, &wmi_list); +mutex_unlock (&list_mutex); +kfree (keymap); +return 0 ; +} + +static int dell_privacy_wmi_remove (struct wmi_device *wdev) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (&wdev->dev); + +mutex_lock (&list_mutex); +list_del (&priv->list); +mutex_unlock (&list_mutex); +return 0 ; +} + +static const struct wmi_device_id dell_wmi_privacy_wmi_id_table[] = { + { .guid_string =DELL_PRIVACY_GUID }, + { }, +}; + +static struct wmi_driver dell_privacy_wmi_driver = { + .driver = { + .name ="dell-privacy" , + }, + .probe = dell_privacy_wmi_probe, + .remove = dell_privacy_wmi_remove, + .id_table = dell_wmi_privacy_wmi_id_table, +}; + +module_wmi_driver (dell_privacy_wmi_driver); + +MODULE_DEVICE_TABLE (wmi, dell_wmi_privacy_wmi_id_table); +MODULE_AUTHOR ("Perry Yuan <[email protected]>" ); +MODULE_DESCRIPTION ("Dell Privacy WMI Driver" ); +MODULE_LICENSE ("GPL" );(quoted diff) +0
-0
b/drivers/platform/x86/dell/dell-privacy-wmi.hQuoted 16 lines
new file mode 100644
index 000000000000..a24893754286drivers/platform/x86/dell/dell-privacy-wmi.h new file +11
-0@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Dell privacy notification driver +* +* Copyright (C) 2021 Dell Inc. All Rights Reserved. +*/ + +#ifndef _DELL_PRIVACY_WMI_H_ +#define _DELL_PRIVACY_WMI_H_ + +#if IS_ENABLED (CONFIG_DELL_PRIVACY )drivers/platform/x86/dell/dell-privacy-wmi.h line 21
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +10
-0+int dell_privacy_has_micmute (void ); +bool dell_privacy_present (void ); +bool dell_privacy_process_event (int type,int code,int status); +#else /* CONFIG_DELL_PRIVACY */ +static inline int dell_privacy_has_micmute (void ) +{ +return -ENODEV ; +} + +static inline int dell_privacy_present (void )^^^It's declared with
boolreturn type a couple lines above.drivers/platform/x86/dell/dell-privacy-wmi.h
Quoted 5 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +5
-0+{ +return -ENODEV ; +} + +static inline void dell_privacy_process_event(int type, int code, intstatus)
^^^^It's declared with
boolreturn type a couple lines above.drivers/platform/x86/dell/dell-privacy-wmi.h line 31
Quoted 5 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +5
-0+{} +#endif /* CONFIG_DELL_PRIVACY */ + +int dell_privacy_acpi_init (void ); +void dell_privacy_acpi_exit (void );These two don't seem to be referenced anywhere?
Review
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +1
-0+#endif (quoted diff) +0
-0
b/drivers/platform/x86/dell/dell-wmi.cQuoted 28 lines
index
bbdb3e860892..8ef9e22a538f100644drivers/platform/x86/dell/dell-wmi.c +2
-1@@ -27,6 +27,7 @@#include <acpi/video.h> #include "dell-smbios.h" #include "dell-wmi-descriptor.h" +#include "dell-privacy-wmi.h" MODULE_AUTHOR ("Matthew Garrett <[email protected]>" );MODULE_AUTHOR ("Pali Rohár <[email protected]>" );@@ -381,6 +382,7 @@ static void dell_wmi_notify(struct wmi_device *wdev,u16 *buffer_entry, *buffer_end;acpi_size buffer_size;int len, i; +int ret;if (obj->type !=ACPI_TYPE_BUFFER ) {pr_warn ("bad response type %x\n" , obj->type);@@ -427,7 +429,6 @@ static void dell_wmi_notify(struct wmi_device *wdev,switch (buffer_entry[1 ]) {case 0x0000 :/* One key pressed or event occurred */ -case 0x0012 :/* Event with extended data occurred */ if (len >2 )dell_wmi_process_key (wdev, buffer_entry[1 ], buffer_entry[2 ]);drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device *wdev, · line 445
Quoted 6 lines
drivers/platform/x86/dell/dell-wmi.c +3
-0@@ -439,6 +440,16 @@ static void dell_wmi_notify(struct wmi_device *wdev,dell_wmi_process_key (wdev, buffer_entry[1 ], buffer_entry[i]);break ; +case 0x0012 : + ret =dell_privacy_present (); +if ((ret) && (len >2 )) {Is the
len > 2check correct?Moreover, I personally don't see any reason to use a new variable here (
ret).If you incorporate the
dell_privacy_present()check intodell_privacy_process_event(), then evenif (len > ?? && dell_privacy_process_event(...)) /* nothing */ ; else if (len > 2) dell_wmi_process_key(...);would work as Hans has already pointed it out. And there'd be no need for
dell_privacy_present()anymore.Quoted 11 lines
drivers/platform/x86/dell/dell-wmi.c +7
-1+dell_privacy_process_event (buffer_entry[1 ], + buffer_entry[3 ], buffer_entry[4 ]); + }else if (len >2 ) { +dell_wmi_process_key (wdev, buffer_entry[1 ], + buffer_entry[2 ]); + } +break ;default :/* Unknown event */ pr_info ("Unknown WMI event type 0x%x\n" , (int )buffer_entry[1 ]); --Quoted 2 lines
2.25.1
Regards,
Barnabás Pőcze
Hi Perry, Barnabás,
Barnabás thank you for your review. I agree with all your remarks.
Perry, Thank you for the new version, this version is looking good. This is almost ready for merging.
Please fix the review remarks from Barnabás. I also have a couple of small review remarks myself below.
Quoted 109 lines · Barnabás Pőcze
Hi
2021. április 4., vasárnap 10:31 keltezéssel, Perry Yuan írta:
Quoted 89 lines
From: Perry Yuan <[email protected]>
add support for Dell privacy driver for the Dell units equipped hardware privacy design, which protect users privacy of audio and camera from hardware level. Once the audio or camera privacy mode activated, any applications will not get any audio or video stream when user pressed ctrl+F4 hotkey, audio privacy mode will be enabled, micmute led will be also changed accordingly
The micmute led is fully controlled by hardware & EC(embedded controller) and camera mute hotkey is Ctrl+F9. Currently design only emitsSW_CAMERA_LENS_COVERevent while the camera lens shutter will be changed by EC & HW(hardware) control*The flow is like this:
1) User presses key. HW does stuff with this key (timeout timer is started)
2) WMI event is emitted from BIOS to kernel
3) WMI event is received by dell-privacy
4)KEY_MICMUTEemitted from dell-privacy
5) Userland picks up key and modifies kcontrol for SW mute
6) Codec kernel driver catches and callsledtrig_audio_set, like this:ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led ? LED_ON :LED_OFF);7) If "LED" is set to on dell-privacy notifies EC, and timeout is cancelled, HW mic mute activated. If EC not notified, HW mic mute will also be activated when timeout used up, it is just later than active ack
Signed-off-by Perry Yuan <[email protected]>---
v5 -> v6:
* addressed feedback from Hans
* addressed feedback from Pierre
* optimize some debug format withdev_dbg()
* remove platform driver,combined privacy acpi driver into single wmi driver file
* optimize sysfs interface with string added to be more clearly reading v4 -> v5:
* addressed feedback from Randy Dunlap
* addressed feedback from Pierre-Louis Bossart
* rebase to latest 5.12 rc4 upstream kernel
* fix some space alignment problem
v3 -> v4:
* fix format forKconfig
* add sysfs document
* add flow comments to the privacy wmi/acpi driver
* addressed feedback from Barnabás Pőcze[Thanks very much]
* exportprivacy_validto make the global state simpler to query
* fix one issue which will block the dell-laptop driver to load when privacy driver invalid
* addressed feedback from Pierre-Louis Bossart,remove the EC ID match v2 -> v3:
* add sysfs attributes doc
v1 -> v2:
* query EC handle from EC driver directly.
* fix some code style.
* addKEY_ENDto keymap array.
* clean platform device when cleanup called
* use hexadecimal format for log print indev_dbg
* remove__set_bitfor the report keys from probe.
* fix keymap leak
* adderr_free_keymapindell_privacy_wmi_probe
* wmi driver will be unregistered ifprivacy_acpi_init()fails
* add sysfs attribute files for user space query.
* add leds micmute driver to privacy acpi
* add more design info the commit info
------ .../testing/sysfs-platform-dell-privacy-wmi | 55 +++ drivers/platform/x86/dell/Kconfig | 14 + drivers/platform/x86/dell/Makefile | 1 + drivers/platform/x86/dell/dell-laptop.c | 23 +- drivers/platform/x86/dell/dell-privacy-wmi.c | 441 ++++++++++++++++++ drivers/platform/x86/dell/dell-privacy-wmi.h | 32 ++ drivers/platform/x86/dell/dell-wmi.c | 13 +- 7 files changed, 572 insertions(+), 7 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi create mode 100644 drivers/platform/x86/dell/dell-privacy-wmi.c create mode 100644 drivers/platform/x86/dell/dell-privacy-wmi.hDocumentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +6
-0@@ -0,0 +1,55 @@ +What: /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/dell_privacy_supported_type +Date: Apr 2021 +KernelVersion: 5.13 +Contact: "[email protected]>" +Description: + Display which dell hardware level privacy devices are supportedDocumentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 16
Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +10
-0+ “Dell Privacy” is a set of HW, FW, and SW features to enhance + Dell’s commitment to platform privacy for MIC, Camera, and + ePrivacy screens. + The supported hardware privacy devices are: +Attributes: + Microphone Mute: + Identifies the local microphone can be muted by hardware, no applications + is available to capture system mic sound + + Camera Shutter:^^^^^^^^^^^^^^^^Spaces used instead of tabs.
Quoted 16 lines
Quoted 6 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +6
-0+ Identifies camera shutter controlled by hardware, which is a micromechanical + shutter assembly that is built onto the camera module to block capturing images + from outside the laptop + + supported: + The privacy device is supported by this systemDocumentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 32
Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +10
-0+ + unsupported: + The privacy device is not supported on this system + + For example to check which privacy devices are supported: + + # cat /sys/bus/wmi/drivers/dell-privacy/6932965F-1671-4CEB-B988-D3AB0A901919/dell_privacy_supported_type + [Microphone Mute] [supported] + [Camera Shutter] [supported] + [ePrivacy Screen] [unsupport]
[unsupport] should be [unsupported] here.
Quoted 204 lines
Quoted 139 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +23
-0+ +What: /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/dell_privacy_current_state +Date: Apr 2021 +KernelVersion: 5.13 +Contact: "[email protected]>" +Description: + Allow user space to check current dell privacy device state. + Describes the Device State class exposed by BIOS which can be + consumed by various applications interested in knowing the Privacy + feature capabilities +Attributes: + muted: + Identifies the privacy device is turned off and cannot send stream to OS applications + + unmuted: + Identifies the privacy device is turned on ,audio or camera driver can get + stream from mic and camera module to OS applications + + For example to check all supported current privacy device states: + + # cat /sys/bus/wmi/drivers/dell-privacy/6932965F-1671-4CEB-B988-D3AB0A901919/dell_privacy_current_state + [Microphone] [unmuted] + [Camera Shutter] [unmuted]drivers/platform/x86/dell/Kconfig +14
-0@@ -204,4 +204,18 @@ config DELL_WMI_SYSMAN To compile this driver as a module, choose M here: the module will be called dell-wmi-sysman. +config DELL_PRIVACY + tristate "Dell Hardware Privacy Support" + depends on ACPI + depends on ACPI_WMI + depends on INPUT + depends on DELL_LAPTOP + depends on LEDS_TRIGGER_AUDIO + select DELL_WMI + help + This driver provides integration with the "Dell Hardware Privacy" feature + of Dell laptops. + + To compile this driver as a module, choose M here: the module will + be called dell_privacy. endif # X86_PLATFORM_DRIVERS_DELLdrivers/platform/x86/dell/Makefile +1
-0@@ -19,3 +19,4 @@ obj-$(CONFIG_DELL_WMI_AIO) += dell-wmi-aio.o obj-$(CONFIG_DELL_WMI_DESCRIPTOR) += dell-wmi-descriptor.o obj-$(CONFIG_DELL_WMI_LED) += dell-wmi-led.o obj-$(CONFIG_DELL_WMI_SYSMAN) += dell-wmi-sysman/ +obj-$(CONFIG_DELL_PRIVACY) += dell-privacy-wmi.odrivers/platform/x86/dell/dell-laptop.c +17
-6@@ -31,6 +31,8 @@#include "dell-rbtn.h" #include "dell-smbios.h" +#include "dell-privacy-wmi.h" +struct quirk_entry {bool touchpad_led;bool kbd_led_not_present;@@ -90,6 +92,7 @@ static struct rfkill *wifi_rfkill;static struct rfkill *bluetooth_rfkill;static struct rfkill *wwan_rfkill;static bool force_rfkill; +static bool has_privacy;module_param (force_rfkill, bool,0444 );MODULE_PARM_DESC (force_rfkill,"enable rfkill on non whitelisted models" );@@ -2206,10 +2209,16 @@ static int __init dell_init(void)if (dell_smbios_find_token (GLOBAL_MIC_MUTE_DISABLE ) &&dell_smbios_find_token (GLOBAL_MIC_MUTE_ENABLE )) { - micmute_led_cdev.brightness =ledtrig_audio_get (LED_AUDIO_MICMUTE ); - ret =led_classdev_register (&platform_device->dev, &micmute_led_cdev); -if (ret <0 ) - goto fail_led; +if (dell_privacy_has_micmute ()) + has_privacy = true; +else + has_privacy = false; +if (!has_privacy) { + micmute_led_cdev.brightness =ledtrig_audio_get (LED_AUDIO_MICMUTE ); + ret =led_classdev_register (&platform_device->dev, &micmute_led_cdev); +if (ret <0 ) + goto fail_led; + } }if (acpi_video_get_backlight_type () != acpi_backlight_vendor)@@ -2257,7 +2266,8 @@ static int __init dell_init(void) fail_get_brightness:backlight_device_unregister (dell_backlight_device); fail_backlight: -led_classdev_unregister (&micmute_led_cdev); +if (!has_privacy) +led_classdev_unregister (&micmute_led_cdev); fail_led:dell_cleanup_rfkill (); fail_rfkill:@@ -2278,7 +2288,8 @@ static void __exit dell_exit(void)touchpad_led_exit ();kbd_led_exit ();backlight_device_unregister (dell_backlight_device); -led_classdev_unregister (&micmute_led_cdev); +if (!has_privacy) +led_classdev_unregister (&micmute_led_cdev);dell_cleanup_rfkill ();if (platform_device) {platform_device_unregister (platform_device);drivers/platform/x86/dell/dell-privacy-wmi.c new file +16
-0@@ -0,0 +1,441 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Dell privacy notification driver +* +* Copyright (C) 2021 Dell Inc. All Rights Reserved. +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/acpi.h> +#include <linux/bitops.h> +#include <linux/input.h> +#include <linux/input/sparse-keymap.h> +#include <linux/list.h> +#include <linux/leds.h> +#include <linux/module.h> drivers/platform/x86/dell/dell-privacy-wmi.c line 26
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+#include <linux/wmi.h> + +#include "dell-privacy-wmi.h" + +#define DELL_PRIVACY_GUID "6932965F-1671-4CEB-B988-D3AB0A901919" +#define MICROPHONE_STATUS BIT(0) +#define CAMERA_STATUS BIT(1) +#define DELL_PRIVACY_AUDIO_EVENT 0x1 +#define DELL_PRIVACY_CAMERA_EVENT 0x2 +#define cdev_to_led (c) container_of(c, struct privacy_wmi_data, cdev)This name is confusing in my opinion. Something like
led_to_privcould be clearer.Quoted 50 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +50
-0+ +/* +* The wmi_list is used to store the privacy_priv struct with mutex protecting +*/ +static LIST_HEAD (wmi_list); +static DEFINE_MUTEX (list_mutex); + +struct privacy_wmi_data { +struct input_dev *input_dev; +struct wmi_device *wdev; +struct list_head list; +struct led_classdev cdev; +u32 features_present; +u32 last_status; +}; + +/* DELL Privacy Type */ +enum dell_hardware_privacy_type { +DELL_PRIVACY_TYPE_AUDIO =0 , +DELL_PRIVACY_TYPE_CAMERA , +DELL_PRIVACY_TYPE_SCREEN , +DELL_PRIVACY_TYPE_MAX , +}; + +static const char *const privacy_types[DELL_PRIVACY_TYPE_MAX ] = { + [DELL_PRIVACY_TYPE_AUDIO ] ="Microphone" , + [DELL_PRIVACY_TYPE_CAMERA ] ="Camera Shutter" , + [DELL_PRIVACY_TYPE_SCREEN ] ="ePrivacy Screen" , +}; + +/* +* Keymap for WMI privacy events of type 0x0012 +*/ +static const struct key_entry dell_wmi_keymap_type_0012[] = { +/* privacy mic mute */ + {KE_KEY ,0x0001 , {KEY_MICMUTE } }, +/* privacy camera mute */ + {KE_SW ,0x0002 , {SW_CAMERA_LENS_COVER } }, + {KE_END ,0 }, +}; + +/* +* global privacy state for other modules to query if the privacy driver loaded successfully +* or no privacy WMI device was detected at initial probe phase +*/ +bool dell_privacy_present (void ) +{ +struct privacy_wmi_data *priv; + +mutex_lock (&list_mutex);
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 84
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+ priv =list_first_entry_or_null (&wmi_list, + struct privacy_wmi_data, + list); +mutex_unlock (&list_mutex); + +return priv; +} +EXPORT_SYMBOL_GPL (dell_privacy_present);
As Barnabás also says below this function is not necessary, please remove it.
Quoted 60 lines
Quoted 19 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +19
-0+ +/* +* Allow other modules to check current dell privacy mic mute state +*/ +int dell_privacy_has_micmute (void ) +{ +struct privacy_wmi_data *priv; +int ret; + +mutex_lock (&list_mutex); + priv =list_first_entry_or_null (&wmi_list, + struct privacy_wmi_data, + list); +/* +* There is no privacy device node yet, so we need to wait +* until the privacy driver has created software node for the micmute device. +* This function will return -EPROBE_DEFER until the privacy device is registered. +*/ +if (!priv) {drivers/platform/x86/dell/dell-privacy-wmi.c line 113
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ ret = -EPROBE_DEFER ; + goto out; + } + ret = priv->features_present &MICROPHONE_STATUS ; +if (!ret) { +dev_err (&priv->wdev->dev,"privacy mic mute feature is not supported: %d\n" , ret); + ret = -ENODEV ; + goto out; + } +dev_err (&priv->wdev->dev,"privacy mic mute feature is supported: %d\n" , ret);I think this could be
dev_info(), but definitely notdev_err(). Although I'd personally move the logging from here to the probe function if you want to log which features are available.retis necessarily 1 here, so I don't think printing it provides additional information.Quoted 24 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +24
-0+ +out: +mutex_unlock (&list_mutex); +return ret; +} +EXPORT_SYMBOL_GPL (dell_privacy_has_micmute); + +/* +* The flow of privacy event: +* 1) User presses key. HW does stuff with this key (timeout is started) +* 2) WMI event is emitted from BIOS +* 3) WMI event is received by dell-privacy +* 4) KEY_MICMUTE emitted from dell-privacy +* 5) Userland picks up key and modifies kcontrol for SW mute +* 6) Codec kernel driver catches and calls ledtrig_audio_set defined by +* dell-privacy-acpi driver. Codec driver will call like this to switch micmute led state. +* ledtrig_audio_set(LED_AUDIO_MICMUTE, micmute_led ? LED_ON :LED_OFF); +* 7) If "LED" is set to on dell-privacy notifies EC,and timeout is cancelled, +* HW mic mute activated. +*/ +bool dell_privacy_process_event (int type,int code,int status) +{ +struct privacy_wmi_data *priv; +const struct key_entry *key;
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 145
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+bool ret = false; + +mutex_lock (&list_mutex); + priv =list_first_entry_or_null (&wmi_list, + struct privacy_wmi_data, + list); +if (!priv) { +dev_err (&priv->wdev->dev,"priv data is NULL\n" );
Please drop the dev_err here, this is expected to happen on devices without privacy features, since the intention is to use this function as dell_privacy_present() + process_event() functionality in one function. Doing things this way is simpler and avoids a race since this function holds the mutex the entire time.
Quoted 53 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 148
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +3
-0+ goto error; + } +I think the rest of the function could be replaced with:
ret =
sparse_keymap_report_event(priv->input_dev, DELL_SCAN_CODE(type, code), 1, true)if (ret) priv->last_status = status;error:
[...](see later a comment for the definition of
DELL_SCAN_CODE())Quoted 7 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +7
-0+ key =sparse_keymap_entry_from_scancode (priv->input_dev, (type <<16 ) | code); +if (!key) { +dev_warn (&priv->wdev->dev,"Unknown key with type 0x%04x and code 0x%04x pressed\n" , + type, code); + goto error; + } +dev_dbg (&priv->wdev->dev,"Key with type 0x%04x and code 0x%04x pressed\n" , type, code);drivers/platform/x86/dell/dell-privacy-wmi.c line 165
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ +switch (code) { +case DELL_PRIVACY_AUDIO_EVENT :/* Mic mute */ +case DELL_PRIVACY_CAMERA_EVENT :/* Camera mute */ + priv->last_status = status; +sparse_keymap_report_entry (priv->input_dev, key,1 , true); + ret = true; +break ; +default : +dev_dbg (&priv->wdev->dev,"unknown event type 0x%04x 0x%04x" , type, code);The capitalization is inconsistent. Please either make all messages lowercase or make them all start with an uppercase letter. (And a newline character is missing.)
Quoted 14 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +14
-0+ } + +error: +mutex_unlock (&list_mutex); +return ret; +} +EXPORT_SYMBOL_GPL (dell_privacy_process_event); + +static ssize_t dell_privacy_supported_type_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +enum dell_hardware_privacy_type type; +struct privacy_wmi_data *priv =dev_get_drvdata (dev);
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 185
Quoted 6 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +6
-0+char *s = buf; +u32 privacy_list; + + privacy_list = priv->features_present; +for (type =DELL_PRIVACY_TYPE_AUDIO ; type <DELL_PRIVACY_TYPE_MAX ; type++) { +if (privacy_types[type]) {Is this check necessary?
No I don't think it is, this check can be removed, good catch.
Quoted 6 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 189
Quoted 6 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +4
-0+if (privacy_list &BIT (type)) + s +=sprintf (s,"[%s] [supported]\n" , privacy_types[type]); +else + s +=sprintf (s,"[%s] [unsupport]\n" , privacy_types[type]);
[unsupport] should be [unsupported] here.
Quoted 4 lines
You can use
sysfs_emit_at()here.
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 195
Quoted 6 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +6
-0+ } + } + +if (s != buf) +/* convert the last space to a newline */ + *(s-1 ) ='\n' ;I believe this is not needed?
Right this is no longer necessary now that we have 1 line per feature.
Quoted 25 lines
Quoted 11 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +9
-0+return (s - buf); +} + +static ssize_t dell_privacy_current_state_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (dev); +enum dell_hardware_privacy_type type;drivers/platform/x86/dell/dell-privacy-wmi.c line 214
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+u32 privacy_state = priv->last_status; +u32 privacy_supported = priv->features_present; +char *s = buf; + +for (type =DELL_PRIVACY_TYPE_AUDIO ; type <DELL_PRIVACY_TYPE_MAX ; type++) { +if (privacy_supported &BIT (type)) { +if (privacy_state &BIT (type)) + s +=sprintf (s,"[%s] [unmuted]\n" , privacy_types[type]); +else + s +=sprintf (s,"[%s] [muted]\n" , privacy_types[type]);
sysfs_emit_at
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 195
Quoted 6 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +6
-0+ } + } + +if (s != buf) +/* convert the last space to a newline */ + *(s-1 ) ='\n' ;not needed?
Ack.
Quoted 35 lines
Quoted 15 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +15
-0+return (s - buf); +} + +static DEVICE_ATTR_RO (dell_privacy_supported_type); +static DEVICE_ATTR_RO (dell_privacy_current_state); + +static struct attribute *privacy_attributes[] = { + &dev_attr_dell_privacy_supported_type.attr, + &dev_attr_dell_privacy_current_state.attr, +NULL , +}; + +static const struct attribute_group privacy_attribute_group = { + .attrs = privacy_attributes +};drivers/platform/x86/dell/dell-privacy-wmi.c line 245
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ +/* +* Describes the Device State class exposed by BIOS which can be consumed by +* various applications interested in knowing the Privacy feature capabilities. +* class DeviceState +* { +* [key, read] string InstanceName; +* [read] boolean ReadOnly; +* [WmiDataId(1), read] uint32 DevicesSupported; +* 0 – None, 0x1 – Microphone, 0x2 – Camera, 0x4 -ePrivacy Screen ^ ^ ^ ^ ^^
Please use a single type of hyphen/dash consistently. One space is enough.drivers/platform/x86/dell/dell-privacy-wmi.c line 247
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +2
-0+* [WmiDataId(2), read] uint32 CurrentState; +* 0:Off; 1:On. Bit0 – Microphone, Bit1 – Camera, Bit2 - ePrivacyScreen ^ ^ ^
Same here.
Quoted 13 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 258
Quoted 11 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +11
-0+* }; +*/ +static int get_current_status (struct wmi_device *wdev) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (&wdev->dev); +union acpi_object *obj_present; +u32 *buffer; +int ret =0 ; + +if (!priv) { +pr_err ("dell privacy priv is NULL\n" );
dev_err?
Ack.
Quoted 116 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 266
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+return -EINVAL ; + } +/* check privacy support features and device states */ + obj_present =wmidev_block_query (wdev,0 ); +if (!obj_present) { +dev_err (&wdev->dev,"failed to read Binary MOF\n" ); + ret = -EIO ; +return ret;return
-EIO?Quoted 9 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +9
-0+ } + +if (obj_present->type !=ACPI_TYPE_BUFFER ) { +dev_err (&wdev->dev,"Binary MOF is not a buffer!\n" ); + ret = -EIO ; + goto obj_free; + } +/* Although it's not technically a failure, this would lead to +* unexpected behavior drivers/platform/x86/dell/dell-privacy-wmi.c line 285
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+*/ +if (obj_present->buffer.length !=8 ) { +dev_err (&wdev->dev,"Dell privacy buffer has unexpected length (%d)!\n" , + obj_present->buffer.length); + ret = -EINVAL ; + goto obj_free; + } + buffer = (u32 *)obj_present->buffer.pointer; + priv->features_present = buffer[0 ]; + priv->last_status = buffer[1 ];It's a minor thing, but I still think it'd more explicit and somewhat better to use
get_unaligned_le32()(orget_unaligned_cpu32()).Quoted 49 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +49
-0+ +obj_free: +kfree (obj_present); +return ret; +} + +static int dell_privacy_micmute_led_set (struct led_classdev *led_cdev, +enum led_brightness brightness) +{ +struct privacy_wmi_data *priv =cdev_to_led (led_cdev); +static char *acpi_method = (char *)"ECAK" ; +acpi_status status; +acpi_handle handle; + + handle =ec_get_handle (); +if (!handle) +return -EIO ; + +if (!acpi_has_method (handle, acpi_method)) +return -EIO ; + + status =acpi_evaluate_object (handle, acpi_method,NULL ,NULL ); +if (ACPI_FAILURE (status)) { +dev_err (&priv->wdev->dev,"Error setting privacy EC ack value: %s\n" , +acpi_format_exception (status)); +return -EIO ; + } + +return 0 ; +} + +/* +* Pressing the mute key activates a time delayed circuit to physically cut +* off the mute. The LED is in the same circuit, so it reflects the true +* state of the HW mute. The reason for the EC "ack" is so that software +* can first invoke a SW mute before the HW circuit is cut off. Without SW +* cutting this off first does not affect the time delayed muting or status +* of the LED but there is a possibility of a "popping" noise. +* +* If the EC receives the SW ack, the circuit will be activated before the +* delay completed. +* +* Exposing as an LED device allows the codec drivers notification path to +* EC ACK to work +*/ +static int dell_privacy_leds_setup (struct device *dev) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (dev); +int ret;drivers/platform/x86/dell/dell-privacy-wmi.c line 344
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ + priv->cdev.name ="dell-privacy::micmute" ; + priv->cdev.max_brightness =1 ; + priv->cdev.brightness_set_blocking = dell_privacy_micmute_led_set; + priv->cdev.default_trigger ="audio-micmute" ; + priv->cdev.brightness =ledtrig_audio_get (LED_AUDIO_MICMUTE ); + ret =devm_led_classdev_register (dev, &priv->cdev); +if (ret) +return ret; +return 0 ;You can replace the last four lines with:
return devm_led_classdev_register(...);drivers/platform/x86/dell/dell-privacy-wmi.c line 355
Quoted 11 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +11
-0+} + +static int dell_privacy_wmi_probe (struct wmi_device *wdev,const void *context) +{ +struct privacy_wmi_data *priv; +struct key_entry *keymap; +int ret, i; + + ret =wmi_has_guid (DELL_PRIVACY_GUID ); +if (!ret) +pr_debug ("Unable to detect available Dell privacy devices: %d\n" , ret);When this branch is taken,
retis necessarily zero, so I don't think printing it provides useful information.
Quoted 2 lines
And I believe this
wmi_has_guid()check is unnecessary since the probe method would not be called if the device didn't have such WMI guid if I'm not mistaken.
Ack, Perry please drop this check.
Quoted 36 lines
Quoted 15 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +15
-0+ + priv =devm_kzalloc (&wdev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + +dev_set_drvdata (&wdev->dev, priv); + priv->wdev = wdev; +/* create evdev passing interface */ + priv->input_dev =devm_input_allocate_device (&wdev->dev); +if (!priv->input_dev) +return -ENOMEM ; + +/* remap the wmi keymap event to new keymap */ + keymap =kcalloc (ARRAY_SIZE (dell_wmi_keymap_type_0012), +sizeof (struct key_entry ),GFP_KERNEL );drivers/platform/x86/dell/dell-privacy-wmi.c line 380
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+if (!keymap) +return -ENOMEM ; + +/* remap the keymap code with Dell privacy key type 0x12 as prefix +* KEY_MICMUTE scancode will be reported as 0x120001 +*/ +for (i =0 ; i <ARRAY_SIZE (dell_wmi_keymap_type_0012); i++) { + keymap[i] = dell_wmi_keymap_type_0012[i]; + keymap[i].code |= (0x0012 <<16 ); + }I still don't see the need for allocating and copying the keymap. Wouldn't the following be sufficient?
#define DELL_SCAN_CODE(type, code) ((type) << 16 | (code)) static const struct key_entry dell_wmi_keymap_type_0012[] = { { KE_KEY, DELL_SCAN_CODE(0x0012, 0x0001), { KEY_MICMUTE } }, { KE_SW, DELL_SCAN_CODE(0x0012, 0x0002), { SW_CAMERA_LENS_COVER } }, { KE_END, 0}, };
Quoted 3 lines
Other Dell drivers potentially merge multiple keymaps, so dynamically allocating the
key_entryarray is justified. Here I see no such need. Can you explain why this copying is done?
I was wondering the same thing when I reviewed v5, but this is consistent with the handling in dell-wmi.c so I'm fine with keeping it as is for consistency. But if you (perry) want to change this to the simpler code which Barnabás is suggesting that is fine too.
Quoted 7 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 383
Quoted 5 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +3
-0+ ret =sparse_keymap_setup (priv->input_dev, keymap,NULL ); +if (ret) +return ret;
keymapis leaked if this or any of the later early-returns are taken.
Right as I mentioned in my review of v5, the "kfree(keymap);" needs to be moved before the "if (ret)" here, so the end results looks like this:
ret = sparse_keymap_setup(priv->input_dev, keymap, NULL); kfree(keymap); if (ret) return ret;
And the kfree(keymap) below goes away.
Quoted 19 lines
Quoted 19 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +17
-0+ + priv->input_dev->dev.parent = &wdev->dev; + priv->input_dev->name ="Dell Privacy Driver" ; + priv->input_dev->id.bustype =BUS_HOST ; + + ret =input_register_device (priv->input_dev); +if (ret) +return ret; + + ret =get_current_status (priv->wdev); +if (ret) +return ret; + + ret =devm_device_add_group (&wdev->dev, &privacy_attribute_group); +if (ret) +return ret; +
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 408
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+ ret =dell_privacy_leds_setup (&priv->wdev->dev); +if (ret) +return ret; + +mutex_lock (&list_mutex); +list_add_tail (&priv->list, &wmi_list); +mutex_unlock (&list_mutex); +kfree (keymap);
This kfree(keymap) needs to be removed. Note that switching to the suggested non copied keymap would get rid of all of this.
Quoted 73 lines
Quoted 50 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +33
-0+return 0 ; +} + +static int dell_privacy_wmi_remove (struct wmi_device *wdev) +{ +struct privacy_wmi_data *priv =dev_get_drvdata (&wdev->dev); + +mutex_lock (&list_mutex); +list_del (&priv->list); +mutex_unlock (&list_mutex); +return 0 ; +} + +static const struct wmi_device_id dell_wmi_privacy_wmi_id_table[] = { + { .guid_string =DELL_PRIVACY_GUID }, + { }, +}; + +static struct wmi_driver dell_privacy_wmi_driver = { + .driver = { + .name ="dell-privacy" , + }, + .probe = dell_privacy_wmi_probe, + .remove = dell_privacy_wmi_remove, + .id_table = dell_wmi_privacy_wmi_id_table, +}; + +module_wmi_driver (dell_privacy_wmi_driver); + +MODULE_DEVICE_TABLE (wmi, dell_wmi_privacy_wmi_id_table); +MODULE_AUTHOR ("Perry Yuan <[email protected]>" ); +MODULE_DESCRIPTION ("Dell Privacy WMI Driver" ); +MODULE_LICENSE ("GPL" );drivers/platform/x86/dell/dell-privacy-wmi.h new file +11
-0@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Dell privacy notification driver +* +* Copyright (C) 2021 Dell Inc. All Rights Reserved. +*/ + +#ifndef _DELL_PRIVACY_WMI_H_ +#define _DELL_PRIVACY_WMI_H_ + +#if IS_ENABLED (CONFIG_DELL_PRIVACY )drivers/platform/x86/dell/dell-privacy-wmi.h line 21
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +10
-0+int dell_privacy_has_micmute (void ); +bool dell_privacy_present (void ); +bool dell_privacy_process_event (int type,int code,int status); +#else /* CONFIG_DELL_PRIVACY */ +static inline int dell_privacy_has_micmute (void ) +{ +return -ENODEV ; +} + +static inline int dell_privacy_present (void )^^^It's declared with
boolreturn type a couple lines above.drivers/platform/x86/dell/dell-privacy-wmi.h line 26
Quoted 5 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +5
-0+{ +return -ENODEV ; +} + +static inline void dell_privacy_process_event (int type,int code,int status)^^^^It's declared with
boolreturn type a couple lines above.
Quoted 7 lines
drivers/platform/x86/dell/dell-privacy-wmi.h line 31
Quoted 5 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +5
-0+{} +#endif /* CONFIG_DELL_PRIVACY */ + +int dell_privacy_acpi_init (void ); +void dell_privacy_acpi_exit (void );These two don't seem to be referenced anywhere?
These no longer exist and should be removed from the header.
Quoted 41 lines
Quoted 32 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +1
-0+#endif drivers/platform/x86/dell/dell-wmi.c +2
-1@@ -27,6 +27,7 @@#include <acpi/video.h> #include "dell-smbios.h" #include "dell-wmi-descriptor.h" +#include "dell-privacy-wmi.h" MODULE_AUTHOR ("Matthew Garrett <[email protected]>" );MODULE_AUTHOR ("Pali Rohár <[email protected]>" );@@ -381,6 +382,7 @@ static void dell_wmi_notify(struct wmi_device *wdev,u16 *buffer_entry, *buffer_end;acpi_size buffer_size;int len, i; +int ret;if (obj->type !=ACPI_TYPE_BUFFER ) {pr_warn ("bad response type %x\n" , obj->type);@@ -427,7 +429,6 @@ static void dell_wmi_notify(struct wmi_device *wdev,switch (buffer_entry[1 ]) {case 0x0000 :/* One key pressed or event occurred */ -case 0x0012 :/* Event with extended data occurred */ if (len >2 )dell_wmi_process_key (wdev, buffer_entry[1 ], buffer_entry[2 ]);drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device *wdev, · line 445
Quoted 6 lines
drivers/platform/x86/dell/dell-wmi.c +3
-0@@ -439,6 +440,16 @@ static void dell_wmi_notify(struct wmi_device *wdev,dell_wmi_process_key (wdev, buffer_entry[1 ], buffer_entry[i]);break ; +case 0x0012 : + ret =dell_privacy_present (); +if ((ret) && (len >2 )) {Is the
len > 2check correct?
Quoted 4 lines
Moreover, I personally don't see any reason to use a new variable here (
ret).If you incorporate the
dell_privacy_present()check intodell_privacy_process_event(),
dell_privacy_process_event() already incorporates a presency check; and by only relying on that check we also avoid a race between the check and processing the event.
Quoted 9 lines
then even
if (len > ?? && dell_privacy_process_event(...)) /* nothing */ ; else if (len > 2) dell_wmi_process_key(...);would work as Hans has already pointed it out. And there'd be no need for
dell_privacy_present()anymore.
Ack, please change this and remove the entire dell_privacy_present() function.
So you should end up with this here:
if (len > 4 && dell_privacy_process_event(buffer_entry[1], buffer_entry[3], buffer_entry[4])) /* nothing */ ; else if (len > 2) dell_wmi_process_key(wdev, buffer_entry[1], dell_wmi_process_key(wdev, buffer_entry[1], break;
Regards,
Hans
Quoted 20 lines
Quoted 13 lines
drivers/platform/x86/dell/dell-wmi.c +7
-1+dell_privacy_process_event (buffer_entry[1 ], + buffer_entry[3 ], buffer_entry[4 ]); + }else if (len >2 ) { +dell_wmi_process_key (wdev, buffer_entry[1 ], + buffer_entry[2 ]); + } +break ;default :/* Unknown event */ pr_info ("Unknown WMI event type 0x%x\n" , (int )buffer_entry[1 ]); --Quoted 2 lines
2.25.1
Regards,
Barnabás Pőcze
Hi Hans, Barnabás.
Thanks for your review very much!
I have no concern to change the most of the comments.
Just one sysfs_emit replacement will cause problem , adding comments at below.
Quoted 552 lines
-----Original Message-----
From: Hans de Goede <[email protected]>
Sent: Wednesday, April 7, 2021 11:16 PM
To: Barnabás Pőcze; Yuan, Perry
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Limonciello, Mario; [email protected]; [email protected]; alsa-devel@alsa- project.org; [email protected]; platform-driver- [email protected]; [email protected]; Dell Client Kernel
Subject: Re: [PATCH v6 1/2] platform/x86: dell-privacy: Add support for Dell hardware privacy[EXTERNAL EMAIL]
Hi Perry, Barnabás,
Barnabás thank you for your review. I agree with all your remarks.
Perry, Thank you for the new version, this version is looking good. This is almost ready for merging.
Please fix the review remarks from Barnabás. I also have a couple of small review remarks myself below.
Quoted 27 lines · Barnabás Pőcze
Hi
2021. április 4., vasárnap 10:31 keltezéssel, Perry Yuan írta:
Quoted 22 lines
From: Perry Yuan <[email protected]>
add support for Dell privacy driver for the Dell units equipped hardware privacy design, which protect users privacy of audio and camera from hardware level. Once the audio or camera privacy mode activated, any applications will not get any audio or video stream when user pressed ctrl+F4 hotkey, audio privacy mode will be enabled, micmute led will be also changed accordingly The micmute led is fully controlled by hardware & EC(embedded controller) and camera mute hotkey is Ctrl+F9. Currently design only emits
SW_CAMERA_LENS_COVERevent while the camera lens shutter will be changed by EC & HW(hardware) control*The flow is like this:
1) User presses key. HW does stuff with this key (timeout timer is started)
2) WMI event is emitted from BIOS to kernel
3) WMI event is received by dell-privacy
4)KEY_MICMUTEemitted from dell-privacy
5) Userland picks up key and modifies kcontrol for SW mute
6) Codec kernel driver catches and callsledtrig_audio_set, like this:ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led ?
LED_ONQuoted 44 lines
Quoted 44 lines
:LED_OFF);
7) If "LED" is set to on dell-privacy notifies EC, and timeout is cancelled, HW mic mute activated. If EC not notified, HW mic mute will also be activated when timeout used up, it is just later than active ackSigned-off-by Perry Yuan <[email protected]>---
v5 -> v6:
* addressed feedback from Hans
* addressed feedback from Pierre
* optimize some debug format withdev_dbg()
* remove platform driver,combined privacy acpi driver into single wmi driver file
* optimize sysfs interface with string added to be more clearly reading
v4 -> v5:
* addressed feedback from Randy Dunlap
* addressed feedback from Pierre-Louis Bossart
* rebase to latest 5.12 rc4 upstream kernel
* fix some space alignment problem
v3 -> v4:
* fix format forKconfig
* add sysfs document
* add flow comments to the privacy wmi/acpi driver
* addressed feedback from Barnabás Pőcze[Thanks very much]
* exportprivacy_validto make the global state simpler to query
* fix one issue which will block the dell-laptop driver to load when privacy driver invalid
* addressed feedback from Pierre-Louis Bossart,remove the EC ID match v2 -> v3:
* add sysfs attributes doc
v1 -> v2:
* query EC handle from EC driver directly.
* fix some code style.
* addKEY_ENDto keymap array.
* clean platform device when cleanup called
* use hexadecimal format for log print indev_dbg
* remove__set_bitfor the report keys from probe.
* fix keymap leak
* adderr_free_keymapindell_privacy_wmi_probe
* wmi driver will be unregistered ifprivacy_acpi_init()fails
* add sysfs attribute files for user space query.
* add leds micmute driver to privacy acpi
* add more design info the commit infoQuoted 8 lines
Quoted 8 lines
---
--- .../testing/sysfs-platform-dell-privacy-wmi | 55 +++ drivers/platform/x86/dell/Kconfig | 14 + drivers/platform/x86/dell/Makefile | 1 + drivers/platform/x86/dell/dell-laptop.c | 23 +- drivers/platform/x86/dell/dell-privacy-wmi.c | 441++++++++++++++++++
drivers/platform/x86/dell/dell-privacy-wmi.h| 32++
Quoted 6 lines
Quoted 6 lines
drivers/platform/x86/dell/dell-wmi.c | 13 +- 7 files changed, 572 insertions(+), 7 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi create mode 100644 drivers/platform/x86/dell/dell-privacy-wmi.c create mode 100644 drivers/platform/x86/dell/dell-privacy-wmi.hQuoted 9 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 1
Quoted 9 lines
diff --git a/Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi b/Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file mode 100644
index 000000000000..a57ddc6a221eDocumentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +1
-0@@ -0,0 +1,55 @@ +What: /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/dell_privacy_supported_type
Quoted 5 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
Quoted 5 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +5
-0+Date: Apr 2021 +KernelVersion: 5.13 +Contact: "[email protected]>" +Description: + Display which dell hardware level privacy devices aresupported
Quoted 1 line
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 7
Quoted 1 line
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +1
-0+ “Dell Privacy” is a set of HW, FW, and SW features toenhance
Quoted 6 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
Quoted 6 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +6
-0+ Dell’s commitment to platform privacy for MIC, Camera, and + ePrivacy screens. + The supported hardware privacy devices are: +Attributes: + Microphone Mute: + Identifies the local microphone can be mutedby hardware, no applications
Quoted 9 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 16
Quoted 3 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +3
-0+ is available to capture system mic sound + + Camera Shutter:^^^^^^^^^^^^^^^^Spaces used instead of tabs.
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 17
Quoted 1 line
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +1
-0+ Identifies camera shutter controlled byhardware, which is a micromechanical
Quoted 1 line
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 18
Quoted 1 line
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +1
-0+ shutter assembly that is built onto thecamera module to block capturing images
Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +4
-0+ from outside the laptop + + supported: + The privacy device is supported by thissystem
Quoted 3 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
Quoted 3 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +3
-0+ + unsupported: + The privacy device is not supported on thissystem
Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +4
-0+ + For example to check which privacy devices are supported: + + # cat /sys/bus/wmi/drivers/dell-privacy/6932965F-1671-4CEB-B988-D3AB0A901919/dell_privacy_supported_type
Quoted 3 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 32
Quoted 3 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +3
-0+ [Microphone Mute] [supported] + [Camera Shutter] [supported] + [ePrivacy Screen] [unsupport][unsupport] should be [unsupported] here.
Quoted 2 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 34
Quoted 2 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +2
-0+ +What: /sys/bus/wmi/devices/6932965F-1671-4CEB-B988-D3AB0A901919/dell_privacy_current_state
Quoted 6 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
Quoted 6 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +6
-0+Date: Apr 2021 +KernelVersion: 5.13 +Contact: "[email protected]>" +Description: + Allow user space to check current dell privacy device state. + Describes the Device State class exposed by BIOS which canbe
Quoted 1 line
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 41
Quoted 1 line
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +1
-0+ consumed by various applications interested in knowing thePrivacy
Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +4
-0+ feature capabilities +Attributes: + muted: + Identifies the privacy device is turned off and cannotsend
Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi
Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +4
-0+stream to OS applications + + unmuted: + Identifies the privacy device is turned on ,audio orcamera driver can get
Quoted 1 line
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 50
Quoted 1 line
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +1
-0+ stream from mic and camera module to OSapplications
Quoted 2 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 52
Quoted 2 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +2
-0+ + For example to check all supported current privacy devicestates:
Quoted 2 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi line 54
Quoted 2 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +2
-0+ + # cat /sys/bus/wmi/drivers/dell-privacy/6932965F-1671-4CEB-B988-D3AB0A901919/dell_privacy_current_state
Quoted 11 lines
Quoted 11 lines
Documentation/ABI/testing/sysfs-platform-dell-privacy-wmi new file +2
-0+ [Microphone] [unmuted] + [Camera Shutter] [unmuted]drivers/platform/x86/dell/Kconfig +0
-0@@ -204,4 +204,18 @@ config DELL_WMI_SYSMAN To compile this driver as a module, choose M here: the module will be called dell-wmi-sysman.Quoted 10 lines
drivers/platform/x86/dell/Kconfig config DELL_WMI_SYSMAN
Quoted 10 lines
drivers/platform/x86/dell/Kconfig +10
-0+config DELL_PRIVACY + tristate "Dell Hardware Privacy Support" + depends on ACPI + depends on ACPI_WMI + depends on INPUT + depends on DELL_LAPTOP + depends on LEDS_TRIGGER_AUDIO + select DELL_WMI + help + This driver provides integration with the "Dell Hardware Privacy"feature
Quoted 11 lines
drivers/platform/x86/dell/Makefile obj-$(CONFIG_DELL_WMI_AIO) +=
Quoted 11 lines
drivers/platform/x86/dell/Kconfig +4
-0+ of Dell laptops. + + To compile this driver as a module, choose M here: the module will + be called dell_privacy. endif # X86_PLATFORM_DRIVERS_DELLdrivers/platform/x86/dell/Makefile +0
-0@@ -19,3 +19,4 @@ obj-$(CONFIG_DELL_WMI_AIO) +=dell-wmi-aio.o
Quoted 23 lines
Quoted 23 lines
drivers/platform/x86/dell/Makefile +1
-0obj-$(CONFIG_DELL_WMI_DESCRIPTOR) += dell-wmi-descriptor.o obj-$(CONFIG_DELL_WMI_LED) += dell-wmi-led.o obj-$(CONFIG_DELL_WMI_SYSMAN) += dell-wmi-sysman/ +obj-$(CONFIG_DELL_PRIVACY) += dell-privacy-wmi.odrivers/platform/x86/dell/dell-laptop.c +2
-0@@ -31,6 +31,8 @@#include "dell-rbtn.h" #include "dell-smbios.h" +#include "dell-privacy-wmi.h" +struct quirk_entry {bool touchpad_led;bool kbd_led_not_present;@@ -90,6 +92,7 @@ static struct rfkill *wifi_rfkill; static structrfkill
*bluetooth_rfkill; static struct rfkill*wwan_rfkill; static boolforce_rfkill;
+static boolhas_privacy;Quoted 7 lines
drivers/platform/x86/dell/dell-laptop.c static int __init dell_init(void)
Quoted 7 lines
module_param(force_rfkill, bool, 0444);MODULE_PARM_DESC(force_rfkill, "enable rfkill on non whitelisted models"); @@ -2206,10 +2209,16 @@ static int__initdell_init(void)drivers/platform/x86/dell/dell-laptop.c +0
-1if (dell_smbios_find_token (GLOBAL_MIC_MUTE_DISABLE ) &&dell_smbios_find_token (GLOBAL_MIC_MUTE_ENABLE )) { - micmute_led_cdev.brightness =
ledtrig_audio_get(LED_AUDIO_MICMUTE);Quoted 1 line
drivers/platform/x86/dell/dell-laptop.c
Quoted 1 line
drivers/platform/x86/dell/dell-laptop.c +0
-1- ret = led_classdev_register(&platform_device->dev,
&micmute_led_cdev);Quoted 8 lines
drivers/platform/x86/dell/dell-laptop.c static int __init dell_init(void)
Quoted 8 lines
drivers/platform/x86/dell/dell-laptop.c +6
-2-if (ret <0 ) - goto fail_led; +if (dell_privacy_has_micmute ()) + has_privacy = true; +else + has_privacy = false; +if (!has_privacy) { + micmute_led_cdev.brightness =
ledtrig_audio_get(LED_AUDIO_MICMUTE);Quoted 1 line
drivers/platform/x86/dell/dell-laptop.c
Quoted 1 line
drivers/platform/x86/dell/dell-laptop.c +1
-0+ ret = led_classdev_register(&platform_device->dev,
&micmute_led_cdev);Quoted 44 lines
Quoted 44 lines
drivers/platform/x86/dell/dell-laptop.c +7
-3+if (ret <0 ) + goto fail_led; + } } if (acpi_video_get_backlight_type() != acpi_backlight_vendor) @@ -2257,7 +2266,8 @@ static int __init dell_init(void) fail_get_brightness:backlight_device_unregister (dell_backlight_device); fail_backlight: -led_classdev_unregister (&micmute_led_cdev); +if (!has_privacy) +led_classdev_unregister (&micmute_led_cdev); fail_led:dell_cleanup_rfkill (); fail_rfkill:@@ -2278,7 +2288,8 @@ static void __exit dell_exit(void)touchpad_led_exit ();kbd_led_exit ();backlight_device_unregister (dell_backlight_device); -led_classdev_unregister (&micmute_led_cdev); +if (!has_privacy) +led_classdev_unregister (&micmute_led_cdev);dell_cleanup_rfkill ();if (platform_device) {platform_device_unregister (platform_device);drivers/platform/x86/dell/dell-privacy-wmi.c new file +11
-0@@ -0,0 +1,441 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Dell privacy notification driver +* +* Copyright (C) 2021 Dell Inc. All Rights Reserved. +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/acpi.h> +#include <linux/bitops.h> Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+#include <linux/input.h> +#include <linux/input/sparse-keymap.h> #include <linux/list.h> +#include <linux/leds.h> #include <linux/module.h> #include +<linux/wmi.h> + +#include "dell-privacy-wmi.h" + +#define DELL_PRIVACY_GUID "6932965F-1671-4CEB-B988-D3AB0A901919"
Quoted 56 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 26
Quoted 5 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +5
-0+#define MICROPHONE_STATUS BIT(0) +#define CAMERA_STATUS BIT(1) +#define DELL_PRIVACY_AUDIO_EVENT 0x1 #define +DELL_PRIVACY_CAMERA_EVENT 0x2 +#define cdev_to_led (c) container_of(c, struct privacy_wmi_data, cdev)This name is confusing in my opinion. Something like
led_to_privcould be clearer.Quoted 46 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +46
-0+ +/* +* The wmi_list is used to store the privacy_priv struct with mutex +protecting */ static LIST_HEAD (wmi_list);static +DEFINE_MUTEX (list_mutex); + +struct privacy_wmi_data { +struct input_dev *input_dev; +struct wmi_device *wdev; +struct list_head list; +struct led_classdev cdev; +u32 features_present; +u32 last_status; +}; + +/* DELL Privacy Type */ +enum dell_hardware_privacy_type { +DELL_PRIVACY_TYPE_AUDIO =0 , +DELL_PRIVACY_TYPE_CAMERA , +DELL_PRIVACY_TYPE_SCREEN , +DELL_PRIVACY_TYPE_MAX , +}; + +static const char *const privacy_types[DELL_PRIVACY_TYPE_MAX ] = { + [DELL_PRIVACY_TYPE_AUDIO ] ="Microphone" , + [DELL_PRIVACY_TYPE_CAMERA ] ="Camera Shutter" , + [DELL_PRIVACY_TYPE_SCREEN ] ="ePrivacy Screen" , }; + +/* +* Keymap for WMI privacy events of type 0x0012 */ static const +struct key_entry dell_wmi_keymap_type_0012[] = { +/* privacy mic mute */ + {KE_KEY ,0x0001 , {KEY_MICMUTE } }, +/* privacy camera mute */ + {KE_SW ,0x0002 , {SW_CAMERA_LENS_COVER } }, + {KE_END ,0 }, +}; + +/* +* global privacy state for other modules to query if the privacy +driver loaded successfully +* or no privacy WMI device was detected at initial probe phase */ +bool dell_privacy_present (void ) { +struct privacy_wmi_data *priv; + +mutex_lock (&list_mutex);Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 84
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+ priv =list_first_entry_or_null (&wmi_list, + struct privacy_wmi_data, + list); +mutex_unlock (&list_mutex); + +return priv; +} +EXPORT_SYMBOL_GPL (dell_privacy_present);As Barnabás also says below this function is not necessary, please remove it.
Quoted 6 lines
Quoted 6 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +6
-0+ +/* +* Allow other modules to check current dell privacy mic mute state +*/ int dell_privacy_has_micmute (void ) { +struct privacy_wmi_data *priv; +int ret;Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+ +mutex_lock (&list_mutex); + priv =list_first_entry_or_null (&wmi_list, + struct privacy_wmi_data, + list); +/* +* There is no privacy device node yet, so we need to wait +* until the privacy driver has created software node for the micmute device.
Quoted 1 line
drivers/platform/x86/dell/dell-privacy-wmi.c line 93
Quoted 1 line
drivers/platform/x86/dell/dell-privacy-wmi.c new file +1
-0+* This function will return -EPROBE_DEFER until the privacy device is registered.
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+*/ +if (!priv) { + ret = -EPROBE_DEFER ; + goto out; + } + ret = priv->features_present &MICROPHONE_STATUS ; +if (!ret) { + dev_err(&priv->wdev->dev, "privacy mic mute feature is notsupported: %d\n", ret);
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 5 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +5
-0+ ret = -ENODEV ; + goto out; + } + dev_err(&priv->wdev->dev, "privacy mic mute feature is supported: +%d\n", ret);I think this could be
dev_info(), but definitely notdev_err(). Although I'd personally move the logging from here to the probe function if you want to log which features are available.retis necessarily 1 here, so I don't think printing it provides additionalinformation.
Quoted 11 lines
Quoted 11 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +9
-0+ +out: +mutex_unlock (&list_mutex); +return ret; +} +EXPORT_SYMBOL_GPL (dell_privacy_has_micmute); + +/* +* The flow of privacy event: Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+ * 1) User presses key. HW does stuff with this key (timeout is +started) + * 2) WMI event is emitted from BIOS + * 3) WMI event is received by dell-privacy + * 4) KEY_MICMUTE emitted from dell-privacy + * 5) Userland picks up key and modifies kcontrol for SW mute + * 6) Codec kernel driver catches and calls ledtrig_audio_set defined by + * dell-privacy-acpi driver. Codec driver will call like this to switchmicmute led state.
Quoted 1 line
drivers/platform/x86/dell/dell-privacy-wmi.c line 124
Quoted 1 line
drivers/platform/x86/dell/dell-privacy-wmi.c new file +1
-0+* ledtrig_audio_set(LED_AUDIO_MICMUTE, micmute_led ?
LED_ON:LED_OFF);Quoted 6 lines
Quoted 6 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +6
-0+* 7) If "LED" is set to on dell-privacy notifies EC,and timeout is cancelled, +* HW mic mute activated. +*/ +bool dell_privacy_process_event (int type,int code,int status) { +struct privacy_wmi_data *priv; +const struct key_entry *key;Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 145
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+bool ret = false; + +mutex_lock (&list_mutex); + priv =list_first_entry_or_null (&wmi_list, + struct privacy_wmi_data, + list); +if (!priv) { +dev_err (&priv->wdev->dev,"priv data is NULL\n" );Please drop the
dev_errhere, this is expected to happen on devices without privacy features, since the intention is to use this function asdell_privacy_present()+process_event()functionality in one function. Doing things this way is simpler and avoids a race since this function holds the mutex the entire time.Quoted 12 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 148
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +3
-0+ goto error; + } +I think the rest of the function could be replaced with:
ret = sparse_keymap_report_event(priv->input_dev,
DELL_SCAN_CODE(type, code), 1, true)if (ret) priv->last_status = status;Quoted 7 lines
error:
[...](see later a comment for the definition of
DELL_SCAN_CODE())drivers/platform/x86/dell/dell-privacy-wmi.c line 142
Quoted 1 line
drivers/platform/x86/dell/dell-privacy-wmi.c new file +1
-0+ key = sparse_keymap_entry_from_scancode(priv->input_dev, (type<< 16) | code);
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 144
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +2
-0+if (!key) { + dev_warn(&priv->wdev->dev, "Unknown key with type0x%04x and code 0x%04x pressed\n",
Quoted 7 lines
Quoted 7 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +7
-0+ type, code); + goto error; + } +dev_dbg (&priv->wdev->dev,"Key with type 0x%04x and code 0x%04x +pressed\n", type, code); + +switch (code) {Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+case DELL_PRIVACY_AUDIO_EVENT :/* Mic mute */ +case DELL_PRIVACY_CAMERA_EVENT :/* Camera mute */ + priv->last_status = status; +sparse_keymap_report_entry (priv->input_dev, key,1 , true); + ret = true; +break ; +default : + dev_dbg(&priv->wdev->dev, "unknown event type 0x%04x0x%04x",
Quoted 18 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 152
Quoted 1 line
drivers/platform/x86/dell/dell-privacy-wmi.c new file +1
-0+type, code);The capitalization is inconsistent. Please either make all messages lowercase or make them all start with an uppercase letter. (And a newline character is missing.)
Quoted 11 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +11
-0+ } + +error: +mutex_unlock (&list_mutex); +return ret; +} +EXPORT_SYMBOL_GPL (dell_privacy_process_event); + +static ssize_t dell_privacy_supported_type_show (struct device *dev, +struct device_attribute *attr, +char *buf)Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+{ +enum dell_hardware_privacy_type type; +struct privacy_wmi_data *priv =dev_get_drvdata (dev); +char *s = buf; +u32 privacy_list; + + privacy_list = priv->features_present; + for (type = DELL_PRIVACY_TYPE_AUDIO; type <
DELL_PRIVACY_TYPE_MAX; type++) {Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 185
Quoted 1 line
drivers/platform/x86/dell/dell-privacy-wmi.c new file +1
-0+if (privacy_types[type]) {Is this check necessary?
No I don't think it is, this check can be removed, good catch.
Quoted 2 lines
Quoted 11 lines
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 182
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +2
-0+if (privacy_list &BIT (type)) + s += sprintf(s, "[%s] [supported]\n",privacy_types[type]);
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 184
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +2
-0+else + s += sprintf(s, "[%s] [unsupport]\n",privacy_types[type]);
[unsupport] should be [unsupported] here.
Quoted 2 lines
You can use
sysfs_emit_at()here.
I found that sysfs_emit_at and sysfs_emit() , will cause the module built failed .
Because it is RO attributes,to save time , I will prefer to keep using the sprintf as before. Perry
Quoted 519 lines
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 195
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +6
-0+ } + } + +if (s != buf) +/* convert the last space to a newline */ + *(s-1 ) ='\n' ;I believe this is not needed?
Right this is no longer necessary now that we have 1 line per feature.
Quoted 16 lines
Quoted 6 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +4
-0+return (s - buf); +} + +static ssize_t dell_privacy_current_state_show(struct device *dev,drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+struct device_attribute *attr, + char *buf) +{ + struct privacy_wmi_data *priv = dev_get_drvdata(dev); +enum dell_hardware_privacy_type type; +u32 privacy_state = priv->last_status; +u32 privacy_supported = priv->features_present; +char *s = buf; + + for (type = DELL_PRIVACY_TYPE_AUDIO; type <
DELL_PRIVACY_TYPE_MAX; type++) {Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 3 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +3
-0+if (privacy_supported &BIT (type)) { +if (privacy_state &BIT (type)) + s += sprintf(s, "[%s] [unmuted]\n",privacy_types[type]);
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 209
Quoted 2 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +2
-0+else + s += sprintf(s, "[%s] [muted]\n",privacy_types[type]);
Quoted 4 lines
sysfs_emit_atQuoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 195
Quoted 6 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +6
-0+ } + } + +if (s != buf) +/* convert the last space to a newline */ + *(s-1 ) ='\n' ;not needed?
Ack.
Quoted 12 lines
Quoted 12 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +12
-0+return (s - buf); +} + +static DEVICE_ATTR_RO (dell_privacy_supported_type); +static DEVICE_ATTR_RO (dell_privacy_current_state); + +static struct attribute *privacy_attributes[] = { + &dev_attr_dell_privacy_supported_type.attr, + &dev_attr_dell_privacy_current_state.attr, +NULL , +}; +Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+static const struct attribute_group privacy_attribute_group = { + .attrs = privacy_attributes +}; + +/* +* Describes the Device State class exposed by BIOS which can be +consumed by +* various applications interested in knowing the Privacy feature capabilities.
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 245
Quoted 6 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +6
-0+* class DeviceState +* { +* [key, read] string InstanceName; +* [read] boolean ReadOnly; +* [WmiDataId(1), read] uint32 DevicesSupported; +* 0 – None, 0x1 – Microphone, 0x2 – Camera, 0x4 -ePrivacy Screen ^ ^ ^ ^ ^^
Please use a single type of hyphen/dash consistently. One space isenough.
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 247
Quoted 4 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +2
-0+* [WmiDataId(2), read] uint32 CurrentState; +* 0:Off; 1:On. Bit0 – Microphone, Bit1 – Camera, Bit2 - ePrivacyScreen ^ ^ ^
Same here.Quoted 12 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 258
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+* }; +*/ +static int get_current_status (struct wmi_device *wdev) { +struct privacy_wmi_data *priv =dev_get_drvdata (&wdev->dev); +union acpi_object *obj_present; +u32 *buffer; +int ret =0 ; + +if (!priv) { +pr_err ("dell privacy priv is NULL\n" );
dev_err?Ack.
Quoted 12 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 266
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+return -EINVAL ; + } +/* check privacy support features and device states */ + obj_present =wmidev_block_query (wdev,0 ); +if (!obj_present) { +dev_err (&wdev->dev,"failed to read Binary MOF\n" ); + ret = -EIO ; +return ret;return
-EIO?Quoted 12 lines
drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 12 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +12
-0+ } + +if (obj_present->type !=ACPI_TYPE_BUFFER ) { +dev_err (&wdev->dev,"Binary MOF is not a buffer!\n" ); + ret = -EIO ; + goto obj_free; + } +/* Although it's not technically a failure, this would lead to +* unexpected behavior +*/ +if (obj_present->buffer.length !=8 ) { + dev_err(&wdev->dev, "Dell privacy buffer has unexpectedlength (%d)!\n",
Quoted 27 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 285
Quoted 7 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +7
-0+ obj_present->buffer.length); + ret = -EINVAL ; + goto obj_free; + } + buffer = (u32 *)obj_present->buffer.pointer; + priv->features_present = buffer[0 ]; + priv->last_status = buffer[1 ];It's a minor thing, but I still think it'd more explicit and somewhat better to use
get_unaligned_le32()(orget_unaligned_cpu32()).Quoted 15 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +15
-0+ +obj_free: +kfree (obj_present); +return ret; +} + +static int dell_privacy_micmute_led_set (struct led_classdev *led_cdev, +enum led_brightness brightness) { +struct privacy_wmi_data *priv =cdev_to_led (led_cdev); +static char *acpi_method = (char *)"ECAK" ; +acpi_status status; +acpi_handle handle; + + handle =ec_get_handle (); +if (!handle)Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 8 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +8
-0+return -EIO ; + +if (!acpi_has_method (handle, acpi_method)) +return -EIO ; + + status =acpi_evaluate_object (handle, acpi_method,NULL ,NULL ); +if (ACPI_FAILURE (status)) { + dev_err(&priv->wdev->dev, "Error setting privacy EC ackvalue: %s\n",
Quoted 47 lines
Quoted 31 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +31
-0+ acpi_format_exception(status)); +return -EIO ; + } + +return 0 ; +} + +/* +* Pressing the mute key activates a time delayed circuit to +physically cut +* off the mute. The LED is in the same circuit, so it reflects the +true +* state of the HW mute. The reason for the EC "ack" is so that +software +* can first invoke a SW mute before the HW circuit is cut off. +Without SW +* cutting this off first does not affect the time delayed muting or +status +* of the LED but there is a possibility of a "popping" noise. +* +* If the EC receives the SW ack, the circuit will be activated +before the +* delay completed. +* +* Exposing as an LED device allows the codec drivers notification +path to +* EC ACK to work +*/ +static int dell_privacy_leds_setup (struct device *dev) { +struct privacy_wmi_data *priv =dev_get_drvdata (dev); +int ret;drivers/platform/x86/dell/dell-privacy-wmi.c line 344
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ + priv->cdev.name ="dell-privacy::micmute" ; + priv->cdev.max_brightness =1 ; + priv->cdev.brightness_set_blocking = dell_privacy_micmute_led_set; + priv->cdev.default_trigger ="audio-micmute" ; + priv->cdev.brightness =ledtrig_audio_get (LED_AUDIO_MICMUTE ); + ret =devm_led_classdev_register (dev, &priv->cdev); +if (ret) +return ret; +return 0 ;You can replace the last four lines with:
return devm_led_classdev_register(...);Quoted 11 lines
drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 11 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +11
-0+} + +static int dell_privacy_wmi_probe (struct wmi_device *wdev,const +void *context) { +struct privacy_wmi_data *priv; +struct key_entry *keymap; +int ret, i; + + ret =wmi_has_guid (DELL_PRIVACY_GUID ); +if (!ret) + pr_debug("Unable to detect available Dell privacydevices: %d\n",
Quoted 7 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 356
Quoted 1 line
drivers/platform/x86/dell/dell-privacy-wmi.c new file +1
-0+ret);When this branch is taken,
retis necessarily zero, so I don't think printing it provides useful information.And I believe this
wmi_has_guid()check is unnecessary since the probe method would not be called if the device didn't have such WMI guidif I'm not mistaken.
Ack, Perry please drop this check.
Quoted 29 lines
Quoted 15 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +15
-0+ + priv =devm_kzalloc (&wdev->dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + +dev_set_drvdata (&wdev->dev, priv); + priv->wdev = wdev; +/* create evdev passing interface */ + priv->input_dev =devm_input_allocate_device (&wdev->dev); +if (!priv->input_dev) +return -ENOMEM ; + +/* remap the wmi keymap event to new keymap */ + keymap =kcalloc (ARRAY_SIZE (dell_wmi_keymap_type_0012), +sizeof (struct key_entry ),GFP_KERNEL );drivers/platform/x86/dell/dell-privacy-wmi.c line 380
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+if (!keymap) +return -ENOMEM ; + +/* remap the keymap code with Dell privacy key type 0x12 as prefix +* KEY_MICMUTE scancode will be reported as 0x120001 +*/ +for (i =0 ; i <ARRAY_SIZE (dell_wmi_keymap_type_0012); i++) { + keymap[i] = dell_wmi_keymap_type_0012[i]; + keymap[i].code |= (0x0012 <<16 ); + }I still don't see the need for allocating and copying the keymap. Wouldn't the following be sufficient?
Quoted 4 lines
#define
DELL_SCAN_CODE(type, code)((type) << 16 | (code))static const struct key_entry dell_wmi_keymap_type_0012[] = { { KE_KEY, DELL_SCAN_CODE(0x0012, 0x0001), { KEY_MICMUTE } }, { KE_SW, DELL_SCAN_CODE(0x0012, 0x0002),{
SW_CAMERA_LENS_COVER} },Quoted 6 lines
{ KE_END, 0},};
Other Dell drivers potentially merge multiple keymaps, so dynamically allocating the
key_entryarray is justified. Here I see no such need. Can you explain why this copying is done?I was wondering the same thing when I reviewed v5, but this is consistent with the handling in
dell-wmi.cso I'm fine with keeping it as is for consistency. But if you (perry) want to change this to the simpler code which Barnabás is suggesting that is fine too.Quoted 7 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 383
Quoted 5 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +3
-0+ ret =sparse_keymap_setup (priv->input_dev, keymap,NULL ); +if (ret) +return ret;
keymapis leaked if this or any of the later early-returns are taken.Right as I mentioned in my review of v5, the "kfree(keymap);" needs to be moved before the "if (ret)" here, so the end results looks like this:
ret = sparse_keymap_setup(priv->input_dev, keymap, NULL); kfree(keymap); if (ret) return ret;And the kfree(keymap) below goes away.
Quoted 16 lines
Quoted 6 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +4
-0+ + priv->input_dev->dev.parent = &wdev->dev; + priv->input_dev->name ="Dell Privacy Driver" ; + priv->input_dev->id.bustype =BUS_HOST ;drivers/platform/x86/dell/dell-privacy-wmi.c
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +10
-0+ + ret =input_register_device (priv->input_dev); +if (ret) +return ret; + + ret =get_current_status (priv->wdev); +if (ret) +return ret; + + ret = devm_device_add_group(&wdev->dev,
&privacy_attribute_group);Quoted 11 lines
drivers/platform/x86/dell/dell-privacy-wmi.c line 408
Quoted 11 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +11
-0+if (ret) +return ret; + + ret =dell_privacy_leds_setup (&priv->wdev->dev); +if (ret) +return ret; + +mutex_lock (&list_mutex); +list_add_tail (&priv->list, &wmi_list); +mutex_unlock (&list_mutex); +kfree (keymap);This kfree(keymap) needs to be removed. Note that switching to the suggested non copied keymap would get rid of all of this.
Quoted 72 lines
Quoted 48 lines
drivers/platform/x86/dell/dell-privacy-wmi.c new file +31
-0+return 0 ; +} + +static int dell_privacy_wmi_remove (struct wmi_device *wdev) { +struct privacy_wmi_data *priv =dev_get_drvdata (&wdev->dev); + +mutex_lock (&list_mutex); +list_del (&priv->list); +mutex_unlock (&list_mutex); +return 0 ; +} + +static const struct wmi_device_id dell_wmi_privacy_wmi_id_table[] = { + { .guid_string =DELL_PRIVACY_GUID }, + { }, +}; + +static struct wmi_driver dell_privacy_wmi_driver = { + .driver = { + .name ="dell-privacy" , + }, + .probe = dell_privacy_wmi_probe, + .remove = dell_privacy_wmi_remove, + .id_table = dell_wmi_privacy_wmi_id_table, }; + +module_wmi_driver (dell_privacy_wmi_driver); + +MODULE_DEVICE_TABLE (wmi, dell_wmi_privacy_wmi_id_table); +MODULE_AUTHOR ("Perry Yuan <[email protected]>" ); +MODULE_DESCRIPTION ("Dell Privacy WMI Driver" ); +MODULE_LICENSE ("GPL" );drivers/platform/x86/dell/dell-privacy-wmi.h new file +10
-0@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Dell privacy notification driver +* +* Copyright (C) 2021 Dell Inc. All Rights Reserved. +*/ + +#ifndef _DELL_PRIVACY_WMI_H_ +#define _DELL_PRIVACY_WMI_H_ +drivers/platform/x86/dell/dell-privacy-wmi.h line 20
Quoted 10 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +10
-0+#if IS_ENABLED (CONFIG_DELL_PRIVACY ) +int dell_privacy_has_micmute (void ); +bool dell_privacy_present (void ); +bool dell_privacy_process_event (int type,int code,int status); +#else /* CONFIG_DELL_PRIVACY */ static inline int +dell_privacy_has_micmute (void ) { +return -ENODEV ; +} + +static inline int dell_privacy_present (void )^^^It's declared with
boolreturn type a couple lines above.drivers/platform/x86/dell/dell-privacy-wmi.h
Quoted 6 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +6
-0+{ +return -ENODEV ; +} + +static inline void dell_privacy_process_event (int type,int code, +int status)^^^^It's declared with
boolreturn type a couple lines above.Quoted 7 lines
drivers/platform/x86/dell/dell-privacy-wmi.h line 31
Quoted 5 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +5
-0+{} +#endif /* CONFIG_DELL_PRIVACY */ + +int dell_privacy_acpi_init (void ); +void dell_privacy_acpi_exit (void );These two don't seem to be referenced anywhere?
These no longer exist and should be removed from the header.
Quoted 14 lines
Quoted 14 lines
drivers/platform/x86/dell/dell-privacy-wmi.h new file +1
-0+#endif drivers/platform/x86/dell/dell-wmi.c +1
-0@@ -27,6 +27,7 @@#include <acpi/video.h> #include "dell-smbios.h" #include "dell-wmi-descriptor.h" +#include "dell-privacy-wmi.h" Quoted 2 lines
Quoted 2 lines
drivers/platform/x86/dell/dell-wmi.c +0
-0MODULE_AUTHOR ("Matthew Garrett <[email protected]>" );
MODULE_AUTHOR("Pali Rohár <[email protected]>"); @@ -381,6 +382,7@@
Quoted 8 lines
drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device *wdev,
Quoted 8 lines
static void dell_wmi_notify(struct
wmi_device*wdev,drivers/platform/x86/dell/dell-wmi.c +1
-0u16 *buffer_entry, *buffer_end;acpi_size buffer_size;int len, i; +int ret;if (obj->type !=ACPI_TYPE_BUFFER ) { pr_warn("bad response type %x\n", obj->type); @@ -427,7+429,6 @@
Quoted 9 lines
drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device
Quoted 9 lines
static void dell_wmi_notify(struct
wmi_device*wdev,drivers/platform/x86/dell/dell-wmi.c +0
-1switch (buffer_entry[1 ]) {case 0x0000 :/* One key pressed or event occurred */ -case 0x0012 :/* Event with extended data occurred */ if (len >2 )dell_wmi_process_key (wdev, buffer_entry[1 ], buffer_entry[2 ]);@@ -439,6 +440,16 @@ static void dell_wmi_notify(struct wmi_device*wdev,
Quoted 10 lines
drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device *wdev, · line 445
Quoted 6 lines
drivers/platform/x86/dell/dell-wmi.c +3
-0dell_wmi_process_key (wdev, buffer_entry[1 ], buffer_entry[i]);break ; +case 0x0012 : + ret =dell_privacy_present (); +if ((ret) && (len >2 )) {Is the
len > 2check correct?Moreover, I personally don't see any reason to use a new variable here
(
ret).Quoted 3 lines
If you incorporate the
dell_privacy_present()check intodell_privacy_process_event(),
dell_privacy_process_event()already incorporates a presency check; and by only relying on that check we also avoid a race between the check and processing the event.Quoted 9 lines
then even
if (len > ?? && dell_privacy_process_event(...)) /* nothing */ ; else if (len > 2) dell_wmi_process_key(...);would work as Hans has already pointed it out. And there'd be no need for
dell_privacy_present()anymore.Ack, please change this and remove the entire
dell_privacy_present()function.So you should end up with this here:
if (len > 4 && dell_privacy_process_event(buffer_entry[1], buffer_entry[3], buffer_entry[4])) /* nothing */ ; else if (len > 2) dell_wmi_process_key(wdev, buffer_entry[1], dell_wmi_process_key(wdev, buffer_entry[1], break;Regards,
Hans
Quoted 4 lines
drivers/platform/x86/dell/dell-wmi.c static void dell_wmi_notify(struct wmi_device · line 447
Quoted 4 lines
drivers/platform/x86/dell/dell-wmi.c +2
-0+ dell_privacy_process_event(buffer_entry[1], + buffer_entry[3],buffer_entry[4]);
Quoted 16 lines
Quoted 11 lines
drivers/platform/x86/dell/dell-wmi.c +5
-1+ }else if (len >2 ) { +dell_wmi_process_key (wdev, buffer_entry[1 ], + buffer_entry[2 ]); + } +break ;default :/* Unknown event */ pr_info ("Unknown WMI event type 0x%x\n" , (int )buffer_entry[1 ]); --2.25.1
Regards,
Barnabás Pőcze