From patchwork Wed Nov 20 16:41:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kurt Borja X-Patchwork-Id: 13881363 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DD2213B58A; Wed, 20 Nov 2024 16:43:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732120986; cv=none; b=Fj2y4kY6kDzfzOs4V5TFAREecG+K2t8jiNTwHohLd8zS+Uxm49tiIE12Of5eHgEylgvi/AXfCqQEOhn/2cVPBD9RnLQ86Kq2Aa3Nu45bku3Y86K+assI/nNEi4inwnmVOzlCJpOzuJc+iH7Y6XMbwIzPTpnDk9AaZO7War1oqNY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732120986; c=relaxed/simple; bh=OoymVpwFMkwuz2aiVMAKjmPOQvN4cofwBGIBPbYhn18=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O0j0hYq5+Y7umNCYVz/2QqeGlVjbLQzum1aphT4NMYubjfTk9SqCi6+jq202gNyd/QkFSInEgBtFGs9lyWLzM0djyKNuIlRwzBi+vvJgYO6aSWerz1rWEeE5LMF91Ol43hRReGbprPgxRy18uDVmf+ChOAt0gYKjaLIirfhvj+w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QA31gkMN; arc=none smtp.client-ip=209.85.215.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QA31gkMN" Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-7f71f2b1370so5035038a12.1; Wed, 20 Nov 2024 08:43:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732120984; x=1732725784; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DskX8Tuw2FCowoWZpTw1NNNCPSabdrvI4T93JXuLkvY=; b=QA31gkMN0xnjxYWQboZENlhnUcozK78SNDnnGa9CmnDs5ooV04PaAZnAUHd2+0dWQ9 FE7/32VvykgtxsfzokfoOiMSb4qBI7m6FVsSjaXL4DtRCzsRfpldaqcQKcDXolHh0unD y3s3W/MfB/m2JzdskDcdRhGKKF0SKGsLVJKDcQFSfSD6vAFNrpY1ITt28SvQm1mUFN15 KS/DmgbGIRsoyZtnqo/K6z0aXWRuIMtidrHl2r9XqIkFBejh/yN2RYeQHC5VN2+2f8u0 dgi5IZX12XBgHHo5xM5XMvFiLFiIUars8vB9Bkzp/chUv3ZruOXmb5W4OdLZ4cMEIAAW 0+Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732120984; x=1732725784; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DskX8Tuw2FCowoWZpTw1NNNCPSabdrvI4T93JXuLkvY=; b=u4sjur80xmuEc8YBlipOfl+DP2c9MsFK2kX9WPSVT7BbDSEYvy/Pw/KucxcUziqmxR aqQHLB8LLlu9LfD8hWRqm1bv0c9CbMrL3Kpp2Ck5rg8/z7cz7HGoA9w4xx3W4VbzVDbl taB9MbpzoCXaRyDRcDHzxCW2D83oksFjj1gDnYrnHuw3ys71zC6prcP80U1ciPjhAHd1 Ttz1PdNYpHBjFC8pkWMrXben0TPtnQifDW30jarhVFCg6FaTx6mdakaAjfhOjJ5V0VBi hWi0l0wC9APKe/iMX4uUu/ZoF8rb4ypKmvWrtE/JckPdH83iFFtiI4kyjVBzLxF6+NEK Xh4Q== X-Forwarded-Encrypted: i=1; AJvYcCUnoVOyip8qySAHh53DfacNxcfr8enizXxupIgiPMpFuOaNAk6AOvgovw2quJpOC6LcWknCpP/OWWzKi2E=@vger.kernel.org, AJvYcCVbmWSQVZtVhQGjnq82KMnxloaFaSdjI15wSfy2dHCZAomm0yLBIlRfgoUX47lY/iJ2f+oGfCoQwASlN05ax8ublDWhXA==@vger.kernel.org X-Gm-Message-State: AOJu0Yw8s0mJQmRKr1ypg21fLLwtS2aIvHq41rVijeSlWmKXFzGBwC+o 1BiiArxbKd5Xiwdzj5ymurp2JOays5er0O93f9OFpsSOc6jjYDVP X-Google-Smtp-Source: AGHT+IGTe1jHqCkRptoyAj6gkJtMDGTCstoPSv+zgzfzndR6HAdJEeZ7cO9ZgTyIDIJR9r2YL1OILQ== X-Received: by 2002:a05:6a21:621:b0:1d8:a67b:9224 with SMTP id adf61e73a8af0-1ddaff54ba5mr2946733637.34.1732120984212; Wed, 20 Nov 2024 08:43:04 -0800 (PST) Received: from localhost.localdomain ([181.84.94.92]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724beeb82a4sm1856233b3a.12.2024.11.20.08.43.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Nov 2024 08:43:03 -0800 (PST) From: Kurt Borja To: kuurtb@gmail.com Cc: Dell.Client.Kernel@dell.com, hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org, mario.limonciello@amd.com, platform-driver-x86@vger.kernel.org, w_armin@gmx.de Subject: [PATCH v2 1/4] alienware-wmi: Migrate to device managed resources Date: Wed, 20 Nov 2024 13:41:30 -0300 Message-ID: <20241120164129.6893-2-kuurtb@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241120163834.6446-3-kuurtb@gmail.com> References: <20241120163834.6446-3-kuurtb@gmail.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 These resources are tied to the platform device lifetime thus make them make them device managed. Also propagate devm_led_classdev_register() in case of failure. This indirectly improves module exit error handling, as potentially not registered led class or sysfs groups are unregistered. Signed-off-by: Kurt Borja --- v2: - led_classdev_register() is now device managed - sysfs_create_group() is now device managed - Removed alienware_zone_exit() because it's empty now --- It seems even if the led class is not registered, led_classdev_unregister fails safely. Same for the sysfs group. If I'm wrong and this is actually a fix please point it out. --- drivers/platform/x86/dell/alienware-wmi.c | 51 ++++++++--------------- 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/drivers/platform/x86/dell/alienware-wmi.c b/drivers/platform/x86/dell/alienware-wmi.c index 77465ed9b449..6760c7627f62 100644 --- a/drivers/platform/x86/dell/alienware-wmi.c +++ b/drivers/platform/x86/dell/alienware-wmi.c @@ -411,8 +411,6 @@ struct wmax_u32_args { }; static struct platform_device *platform_device; -static struct device_attribute *zone_dev_attrs; -static struct attribute **zone_attrs; static struct platform_zone *zone_data; static struct platform_profile_handler pp_handler; static enum wmax_thermal_mode supported_thermal_profiles[PLATFORM_PROFILE_LAST]; @@ -624,10 +622,13 @@ static ssize_t store_control_state(struct device *dev, static DEVICE_ATTR(lighting_control_state, 0644, show_control_state, store_control_state); -static int alienware_zone_init(struct platform_device *dev) +static int alienware_zone_init(struct platform_device *pdev) { u8 zone; char *name; + struct device_attribute *zone_dev_attrs; + struct attribute **zone_attrs; + int ret; if (interface == WMAX) { lighting_control_state = WMAX_RUNNING; @@ -644,28 +645,25 @@ static int alienware_zone_init(struct platform_device *dev) * the lighting control + null terminated * - zone_data num_zones is for the distinct zones */ - zone_dev_attrs = - kcalloc(quirks->num_zones + 1, sizeof(struct device_attribute), - GFP_KERNEL); + zone_dev_attrs = devm_kcalloc(&pdev->dev, quirks->num_zones + 1, + sizeof(struct device_attribute), GFP_KERNEL); if (!zone_dev_attrs) return -ENOMEM; - zone_attrs = - kcalloc(quirks->num_zones + 2, sizeof(struct attribute *), - GFP_KERNEL); + zone_attrs = devm_kcalloc(&pdev->dev, quirks->num_zones + 2, + sizeof(struct attribute *), GFP_KERNEL); if (!zone_attrs) return -ENOMEM; - zone_data = - kcalloc(quirks->num_zones, sizeof(struct platform_zone), - GFP_KERNEL); + zone_data = devm_kcalloc(&pdev->dev, quirks->num_zones, + sizeof(struct platform_zone), GFP_KERNEL); if (!zone_data) return -ENOMEM; for (zone = 0; zone < quirks->num_zones; zone++) { - name = kasprintf(GFP_KERNEL, "zone%02hhX", zone); - if (name == NULL) - return 1; + name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "zone%02hhX", zone); + if (!name) + return -ENOMEM; sysfs_attr_init(&zone_dev_attrs[zone].attr); zone_dev_attrs[zone].attr.name = name; zone_dev_attrs[zone].attr.mode = 0644; @@ -678,24 +676,11 @@ static int alienware_zone_init(struct platform_device *dev) zone_attrs[quirks->num_zones] = &dev_attr_lighting_control_state.attr; zone_attribute_group.attrs = zone_attrs; - led_classdev_register(&dev->dev, &global_led); - - return sysfs_create_group(&dev->dev.kobj, &zone_attribute_group); -} - -static void alienware_zone_exit(struct platform_device *dev) -{ - u8 zone; + ret = devm_led_classdev_register(&pdev->dev, &global_led); + if (ret < 0) + return ret; - sysfs_remove_group(&dev->dev.kobj, &zone_attribute_group); - led_classdev_unregister(&global_led); - if (zone_dev_attrs) { - for (zone = 0; zone < quirks->num_zones; zone++) - kfree(zone_dev_attrs[zone].attr.name); - } - kfree(zone_dev_attrs); - kfree(zone_data); - kfree(zone_attrs); + return devm_device_add_group(&pdev->dev, &zone_attribute_group); } static acpi_status alienware_wmax_command(void *in_args, size_t in_size, @@ -1236,7 +1221,6 @@ static int __init alienware_wmi_init(void) return 0; fail_prep_zones: - alienware_zone_exit(platform_device); remove_thermal_profile(); fail_prep_thermal_profile: fail_prep_deepsleep: @@ -1256,7 +1240,6 @@ module_init(alienware_wmi_init); static void __exit alienware_wmi_exit(void) { if (platform_device) { - alienware_zone_exit(platform_device); remove_hdmi(platform_device); remove_thermal_profile(); platform_device_unregister(platform_device); From patchwork Wed Nov 20 16:43:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kurt Borja X-Patchwork-Id: 13881364 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D890D153801; Wed, 20 Nov 2024 16:43:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732121026; cv=none; b=iv56I/d+Yye1a7H1uLBoA+KmGuacE5t+KRqhCM7tGcphfsCelui1Urv+JekqSEFJYMB5hLe0wU0lbt9Lw6uDyA0Pz9NvzyyNcai6sMN2rRl8+eI3mKr9yOXEMsUwtlvGfOYxkeTA3FJUui8ZDG3TtYJzJd2c5y0EBNkcj+mDf+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732121026; c=relaxed/simple; bh=qoRKPifNpwbHxIrkRiZGC9o4/ZMOh/cdw8ZUMqvXrmY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oKtWXfRLAXXpWhhM9bM+F80r+yY+XIaWdkJPziK7XHE7VXC+1qCZGgG2II7J4hqcxSA0Oqoqp1OTzSSShXYeI1/XZLHF2iAwui4VKjmkkfyO5PASfV2Q8DsuqNbOZvdFTgs4FqzHakFhXukP3Wp/vR2TgpTGXvRzB0Cg3e+FK1I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=l5LdfClx; arc=none smtp.client-ip=209.85.215.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="l5LdfClx" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-7ed9c16f687so6589a12.0; Wed, 20 Nov 2024 08:43:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732121024; x=1732725824; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rY4MrtcqVyuIerAVdHZZzP/4uqpO8ITrRAcC2cys/es=; b=l5LdfClxQeGOBJDm6kAzxeWgTcM3R5hZSI3biQloZq/c8O1EfpjwaLfX3UDAR1ErsB V9m1GGFC0HAbdCB8bzJhAZwwk7SJpEfp8nzND1zVzsyKSEKNG8pwglk5Fauyd5rD2xHs I4PZa7LZDOSyu20eSNvuK4Nz6bHrOhzADXGDZNBJuMsl3WN3/ALoBnoAMnxDLP4a1Kc+ RArtIO+Ql7zZLEIibS6kxkBwTFYFr/ApW0h2g/6KrTgBubEOGd0drselARBBM/yuXC8z JRohW8W+dpURoV5fHM7RXN1PaWBwhmZ3yIkZqHGiceCRLJnVSi+ltFP9WOKgd89fgZYF eRAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732121024; x=1732725824; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rY4MrtcqVyuIerAVdHZZzP/4uqpO8ITrRAcC2cys/es=; b=QJ3FSqT9HYEagC3RpUDEPHNqegsPGUfE80dR3J5A3Ms+jwaVuA+nX7w4gK6HratSzk KOz7EYxT/Sn5XZbe11UxGx/+GVKKIasUVhHKHqf24qu01HpQazztaKL+07U53RaKYZRX A+V8PU1nbE5pA3HSJfgxKIWVpjOAKPKCBcmysxFygBj4QoopF4zjMfg+lIjDw3BYEQO2 RtCSJX8UsbCttNAWv/kfcU2G/cnFWXqwctZRGhY81S63OuQtnC2L+IkIhkAFqWjcHuts zZwcFPUNdKZkuNPtU86EolWA78m0xm2QHrz0+bxOHBs9e1nGsiqdNR+GkwBgtIaISQGa MdBw== X-Forwarded-Encrypted: i=1; AJvYcCW3YokGdMnjXqFL6flf717Em/QJkAWmOgb5cYbC/KeZCnnubPzIAklILExYJ2qC/vgw8C/s/N2+RvFbJE8=@vger.kernel.org, AJvYcCWxhv+BTZDXSOw85cabGZwasgh4cBMrRppQA/G9UGYfEGFdCsMPQs0AUnIoZZfTrC+3XK/LKbCUhm9Ohdt+lj8f11mg9w==@vger.kernel.org X-Gm-Message-State: AOJu0YzXseU9JShEUGdGQO2r/fGZaCI81F5gD5nwM+m13rdMHq3Zb2tF DaokGlw89QezTVaUPbSbsQ/od8iEyZMAqOgI+Vi0FivYrrd2a2/c X-Google-Smtp-Source: AGHT+IH4f9DJqyCERcRoaTWN3u2lPuc/Tl4KK60jt8i94AdWpvBw1cuYr1gKIuUxeh5zLQWIMqgb0w== X-Received: by 2002:a05:6a20:734d:b0:1dc:154a:81fb with SMTP id adf61e73a8af0-1ddb06251camr4852097637.44.1732121022739; Wed, 20 Nov 2024 08:43:42 -0800 (PST) Received: from localhost.localdomain ([181.84.94.92]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7fb72420decsm6192116a12.9.2024.11.20.08.43.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Nov 2024 08:43:42 -0800 (PST) From: Kurt Borja To: kuurtb@gmail.com Cc: Dell.Client.Kernel@dell.com, hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org, mario.limonciello@amd.com, platform-driver-x86@vger.kernel.org, w_armin@gmx.de Subject: [PATCH v2 2/4] alienware-wmi: Improves sysfs groups creation Date: Wed, 20 Nov 2024 13:43:15 -0300 Message-ID: <20241120164314.7177-2-kuurtb@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241120163834.6446-3-kuurtb@gmail.com> References: <20241120163834.6446-3-kuurtb@gmail.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Devices with hdmi_mux, amplifier or deepslp quirks create a sysfs group for each available feature. To accomplish this, helper create/remove functions were called on module init, but they had the following problems: - Create helpers called remove helpers on failure, which in turn tried to remove the sysfs group that failed to be created - If group creation failed mid way, previous successfully created groups were not cleaned up - Module exit only removed hdmi_mux group To improve this, drop all helpers and let the platform driver manage these sysfs groups, while controlling visibility with their respective quirks. Signed-off-by: Kurt Borja --- v2: - Drop the helpers approach in favor of letting the driver manage the wmax sysfs groups --- Again I think not cleaning up created sysfs group is not actually a bug so this is only an improvement. --- drivers/platform/x86/dell/alienware-wmi.c | 112 +++++++--------------- 1 file changed, 36 insertions(+), 76 deletions(-) diff --git a/drivers/platform/x86/dell/alienware-wmi.c b/drivers/platform/x86/dell/alienware-wmi.c index 6760c7627f62..ecab14d90b27 100644 --- a/drivers/platform/x86/dell/alienware-wmi.c +++ b/drivers/platform/x86/dell/alienware-wmi.c @@ -410,17 +410,12 @@ struct wmax_u32_args { u8 arg3; }; + static struct platform_device *platform_device; static struct platform_zone *zone_data; static struct platform_profile_handler pp_handler; static enum wmax_thermal_mode supported_thermal_profiles[PLATFORM_PROFILE_LAST]; -static struct platform_driver platform_driver = { - .driver = { - .name = "alienware-wmi", - } -}; - static struct attribute_group zone_attribute_group = { .name = "rgb_zones", }; @@ -781,6 +776,12 @@ static ssize_t toggle_hdmi_source(struct device *dev, return count; } +static bool hdmi_group_visible(struct kobject *kobj) +{ + return quirks->hdmi_mux; +} +DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(hdmi); + static DEVICE_ATTR(cable, S_IRUGO, show_hdmi_cable, NULL); static DEVICE_ATTR(source, S_IRUGO | S_IWUSR, show_hdmi_source, toggle_hdmi_source); @@ -793,25 +794,10 @@ static struct attribute *hdmi_attrs[] = { static const struct attribute_group hdmi_attribute_group = { .name = "hdmi", + .is_visible = SYSFS_GROUP_VISIBLE(hdmi), .attrs = hdmi_attrs, }; -static void remove_hdmi(struct platform_device *dev) -{ - if (quirks->hdmi_mux > 0) - sysfs_remove_group(&dev->dev.kobj, &hdmi_attribute_group); -} - -static int create_hdmi(struct platform_device *dev) -{ - int ret; - - ret = sysfs_create_group(&dev->dev.kobj, &hdmi_attribute_group); - if (ret) - remove_hdmi(dev); - return ret; -} - /* * Alienware GFX amplifier support * - Currently supports reading cable status @@ -838,6 +824,12 @@ static ssize_t show_amplifier_status(struct device *dev, return sysfs_emit(buf, "unconnected connected [unknown]\n"); } +static bool amplifier_group_visible(struct kobject *kobj) +{ + return quirks->amplifier; +} +DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(amplifier); + static DEVICE_ATTR(status, S_IRUGO, show_amplifier_status, NULL); static struct attribute *amplifier_attrs[] = { @@ -847,25 +839,10 @@ static struct attribute *amplifier_attrs[] = { static const struct attribute_group amplifier_attribute_group = { .name = "amplifier", + .is_visible = SYSFS_GROUP_VISIBLE(amplifier), .attrs = amplifier_attrs, }; -static void remove_amplifier(struct platform_device *dev) -{ - if (quirks->amplifier > 0) - sysfs_remove_group(&dev->dev.kobj, &lifier_attribute_group); -} - -static int create_amplifier(struct platform_device *dev) -{ - int ret; - - ret = sysfs_create_group(&dev->dev.kobj, &lifier_attribute_group); - if (ret) - remove_amplifier(dev); - return ret; -} - /* * Deep Sleep Control support * - Modifies BIOS setting for deep sleep control allowing extra wakeup events @@ -916,6 +893,12 @@ static ssize_t toggle_deepsleep(struct device *dev, return count; } +static bool deepsleep_group_visible(struct kobject *kobj) +{ + return quirks->deepslp; +} +DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(deepsleep); + static DEVICE_ATTR(deepsleep, S_IRUGO | S_IWUSR, show_deepsleep_status, toggle_deepsleep); static struct attribute *deepsleep_attrs[] = { @@ -925,25 +908,10 @@ static struct attribute *deepsleep_attrs[] = { static const struct attribute_group deepsleep_attribute_group = { .name = "deepsleep", + .is_visible = SYSFS_GROUP_VISIBLE(deepsleep), .attrs = deepsleep_attrs, }; -static void remove_deepsleep(struct platform_device *dev) -{ - if (quirks->deepslp > 0) - sysfs_remove_group(&dev->dev.kobj, &deepsleep_attribute_group); -} - -static int create_deepsleep(struct platform_device *dev) -{ - int ret; - - ret = sysfs_create_group(&dev->dev.kobj, &deepsleep_attribute_group); - if (ret) - remove_deepsleep(dev); - return ret; -} - /* * Thermal Profile control * - Provides thermal profile control through the Platform Profile API @@ -1151,6 +1119,20 @@ static void remove_thermal_profile(void) platform_profile_remove(); } +const struct attribute_group *wmax_groups[] = { + &hdmi_attribute_group, + &lifier_attribute_group, + &deepsleep_attribute_group, + NULL +}; + +static struct platform_driver platform_driver = { + .driver = { + .name = "alienware-wmi", + .dev_groups = wmax_groups, + } +}; + static int __init alienware_wmi_init(void) { int ret; @@ -1190,24 +1172,6 @@ static int __init alienware_wmi_init(void) if (ret) goto fail_platform_device2; - if (quirks->hdmi_mux > 0) { - ret = create_hdmi(platform_device); - if (ret) - goto fail_prep_hdmi; - } - - if (quirks->amplifier > 0) { - ret = create_amplifier(platform_device); - if (ret) - goto fail_prep_amplifier; - } - - if (quirks->deepslp > 0) { - ret = create_deepsleep(platform_device); - if (ret) - goto fail_prep_deepsleep; - } - if (quirks->thermal) { ret = create_thermal_profile(); if (ret) @@ -1223,9 +1187,6 @@ static int __init alienware_wmi_init(void) fail_prep_zones: remove_thermal_profile(); fail_prep_thermal_profile: -fail_prep_deepsleep: -fail_prep_amplifier: -fail_prep_hdmi: platform_device_del(platform_device); fail_platform_device2: platform_device_put(platform_device); @@ -1240,7 +1201,6 @@ module_init(alienware_wmi_init); static void __exit alienware_wmi_exit(void) { if (platform_device) { - remove_hdmi(platform_device); remove_thermal_profile(); platform_device_unregister(platform_device); platform_driver_unregister(&platform_driver); From patchwork Wed Nov 20 16:43:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kurt Borja X-Patchwork-Id: 13881371 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D273F148FE8; Wed, 20 Nov 2024 16:44:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732121046; cv=none; b=Wew6l/P4WTsHCmcktGse+kD8Jv8z2THwHyLnDuPR2LhACc+SAbSEi9PZqNpiuIyrSpd3KvNM/b8q0Xj85rMIegFqKuQAeboL2KHa2OdRzsbOzxzisfbbx97NLjhsGGy7usWv3MucbIpfB5WzSvPCzNVR35++YERsPTiISnDrN14= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732121046; c=relaxed/simple; bh=VCGY9U7LwXliYd6d+9B7ied1jKmWIaArbzCfTm1DXuo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J7KnsYjq0yCWTPFZxHorSBKrOkoJkvX51s2XDQg/kkrAUtLCWLi2bjOVg43pszGJ31MBuW4TdXhv9rlr3o534YprBb4h9tqMeJAVRFP0brUXD/kopVHHih+oDn/OhBxzhFSOnvPkUTZhHpGRGvJ2WfxmuJCTru89FpDNvmHi4go= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Khhn0moY; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Khhn0moY" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2128383b86eso8285ad.2; Wed, 20 Nov 2024 08:44:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732121044; x=1732725844; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1vXq/v2AMJrAH9GOZRUpvetNG/P2rLtArw5ggNX+AwQ=; b=Khhn0moY5hlzQJspLmH5fh+iNNcOjIhbL7MAA0nJ3w/byK2bA0+zZEZjvFtrie05dU N2n0p23i1gadN+nNOXfiJhjeLrbJpNFsXlnGZ4tiEEFLkreOEsCbfRO7jcWbOhFFZ7E2 F9ShsaCUDYEGV4cbbKJr/Xih6ss13t+SKJ6ZHAN8BjpSSy9quJwYoFch0rpzGQyQAgdO 8zjShw+aMkKBqIncnACnVc9X8x4Iznyctpx55V1EQDSxhaTE3AoQv9W5yDP5gDcfjtku fEPmKoVhx2Um1tUPtcEwpJtbv82KkiiCKsD9FWY0VMVk+fAOEoHaKjvUCAKTequCVMXE e6rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732121044; x=1732725844; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1vXq/v2AMJrAH9GOZRUpvetNG/P2rLtArw5ggNX+AwQ=; b=nj2ALoEnOMgNqkFucLDFIPoehz74RYA4bnLzHuaY5Iwkz3CxMDAl10mZ8qcdaK5/x9 FuHWq3OR+J5dN8mnUREI9YxWESA31mQfPUf5Oa6DHgcTGSEKlHDcjouWPl+fSt0Zv3jE p4dvq8XlMlaGTEny2pR6iMF8qbLYy1XDSAd62pBeIawAs6/aBR383H4xSLdGkmk+OoA9 AIxWcHoOdS5o1egpNfU2rkTU3JaA5Bvcz0khH1rzx1GUuvdPyUCCYKBkOFsm3K7Ci+4J Aj6N9BN7ZVTxp5cRiWQBvRIvUOiUwAsKgbyUd0rZBCNc5l+rMj4QCKIexOMG8T3FAjka lcBg== X-Forwarded-Encrypted: i=1; AJvYcCWs83J2LlQn16Chol9qlft3vZk080E0WcRg8BMZCoWjgNJgjozamngdpH8OF4S8qdOrZHkjZF1fmstbQRqsAvaFdYmCqg==@vger.kernel.org, AJvYcCXja4mLSp8dgR4Km0PSkRzO16cTcdQB5O2SM/TS3ULP4qnEoP0IAwu3dgw9gRpJRaCNmCdDVsbAqzCPEVc=@vger.kernel.org X-Gm-Message-State: AOJu0YwXeE8gBtt60AvwkxZNnpT9Ude9pwejz/UoiLWxNGbVNn4x5IbC WEYQ73Gnwidr44imK9XQkIGT5u5W0psCaiAB81/6odTFMMr49dIO X-Google-Smtp-Source: AGHT+IE2ZNOi976fSbaTwURst4LgXE6RnNg00hQA2pr90t3Ffu1ZFVaejX9M0pVhEjAL8iJkyf8dxg== X-Received: by 2002:a17:903:251:b0:20c:9d8d:1f65 with SMTP id d9443c01a7336-2126c11bf0fmr42262905ad.30.1732121044085; Wed, 20 Nov 2024 08:44:04 -0800 (PST) Received: from localhost.localdomain ([181.84.94.92]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21253806c73sm32467485ad.157.2024.11.20.08.44.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Nov 2024 08:44:03 -0800 (PST) From: Kurt Borja To: kuurtb@gmail.com Cc: Dell.Client.Kernel@dell.com, hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org, mario.limonciello@amd.com, platform-driver-x86@vger.kernel.org, w_armin@gmx.de Subject: [PATCH v2 3/4] alienware-wmi: Simplify platform device creation Date: Wed, 20 Nov 2024 13:43:49 -0300 Message-ID: <20241120164348.7326-2-kuurtb@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241120163834.6446-3-kuurtb@gmail.com> References: <20241120163834.6446-3-kuurtb@gmail.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Simplify platform device creation by using platform_device_register_simple(). Reviewed-by: Mario Limonciello Signed-off-by: Kurt Borja --- v2: - Unchanged --- drivers/platform/x86/dell/alienware-wmi.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/platform/x86/dell/alienware-wmi.c b/drivers/platform/x86/dell/alienware-wmi.c index ecab14d90b27..512f6b22585c 100644 --- a/drivers/platform/x86/dell/alienware-wmi.c +++ b/drivers/platform/x86/dell/alienware-wmi.c @@ -1163,14 +1163,13 @@ static int __init alienware_wmi_init(void) ret = platform_driver_register(&platform_driver); if (ret) goto fail_platform_driver; - platform_device = platform_device_alloc("alienware-wmi", PLATFORM_DEVID_NONE); - if (!platform_device) { - ret = -ENOMEM; + + platform_device = platform_device_register_simple("alienware-wmi", + PLATFORM_DEVID_NONE, NULL, 0); + if (IS_ERR(platform_device)) { + ret = PTR_ERR(platform_device); goto fail_platform_device1; } - ret = platform_device_add(platform_device); - if (ret) - goto fail_platform_device2; if (quirks->thermal) { ret = create_thermal_profile(); @@ -1187,9 +1186,7 @@ static int __init alienware_wmi_init(void) fail_prep_zones: remove_thermal_profile(); fail_prep_thermal_profile: - platform_device_del(platform_device); -fail_platform_device2: - platform_device_put(platform_device); + platform_device_unregister(platform_device); fail_platform_device1: platform_driver_unregister(&platform_driver); fail_platform_driver: From patchwork Wed Nov 20 16:44:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kurt Borja X-Patchwork-Id: 13881372 Received: from mail-oa1-f43.google.com (mail-oa1-f43.google.com [209.85.160.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C446145324; Wed, 20 Nov 2024 16:44:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732121061; cv=none; b=FmynE3UYi49t4kpa1nVbebbSeZNjq9XE6jqD0heb9k56oXnTFyCyRoGgdgEHHouK8uwnB+DyHlxKdUmjFGzPMevluBPUl+DnfC6iEfZvmVwcaeX6R18ashDVBr9e4eCaz027GIJyntVXLfponyx9J5HuNJfNJ5ro+r4R3shDerM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732121061; c=relaxed/simple; bh=JEpLazsZjAg5nNc1Jsdqele5JGu5yU/uzWcLgQUt3qA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TLAmS2PlqEa/RMkCW8ud2PuK3mjri6nVryTy+7TBHwRlW7i0ZB9gu/8TQKSYi5DhY4+OVdd0HJw/PvRaUruNYxXbXzeghr1I09bnarWKon6p/EoqXf0bwRjm6J6+7B+fkhEfuBMD7hE0OWJoVHlwmkNgiqPy+HNXuavCJuCkLuM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ip6V25f5; arc=none smtp.client-ip=209.85.160.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ip6V25f5" Received: by mail-oa1-f43.google.com with SMTP id 586e51a60fabf-296bff3f5e8so1183170fac.2; Wed, 20 Nov 2024 08:44:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732121058; x=1732725858; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=I4SEWInomL306OQQOdTEh7Ay90+RuyHjfWpHiTKMYlo=; b=Ip6V25f5VEnyjju/rmD48VDpPjCMm2Gpfa/mP4hQXgT9hcNtqeIVzMzbolrBJadWmx C2bQtoK7RU/40KRNq/BP4gIYGaxch5fO/VwGJKOoY6ZBp3YmGMg4qGghovfUTqK54kdt wXfm61ofBkgQk0HnjH5gkXrMUSop98nrhnXhUKml7MV7ol1HvhVCFxh7hWmhS5BOsxuT qJ8maDp/58GbAmuDdNMsiaWlmTD6yx1dB/DCObKbRz9YOmNZSp6HXU8JedIGMAxvQE9l RPMvAzI92VRzHNZBk9iBFDXHz2nnkq3gtWKFlQaQCeCG7rsjMQtPDK3FDlfyX/+i687S +Hfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732121058; x=1732725858; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I4SEWInomL306OQQOdTEh7Ay90+RuyHjfWpHiTKMYlo=; b=LhPS7eRI40UWK5OD9+cggjBzXAQsSUfNZ48cWumNEbHJtMW35ifxTnHU5mpItEqkAf lL7iHufUlOOs0UkZyXLK/WL8l+1XGP0kuChONOY3+P7VoeVvQWigZ8wbNbDbHAeZs6Bv 00o3iyjW9/CrG0+XzZ6gz629STLja4O6OsZIXt5/0i8v77gyCddcs5me5kOk/btHUyC1 Gqi1+Ckl/jaCsqFOgBIRVY6DiZmbp0NLlF0qKR/dh3Sae2k4debqlR6/FtScDC3SGi1J qQ/Nb9XuE4H23VmV/VNG+MIOAaTHvXQp5N21a3BeVfKJfKbBRpDIKhyBjAOzzhpDkehY gBiA== X-Forwarded-Encrypted: i=1; AJvYcCVYREoFArL/DoxwkjPkrLuLGs4bnOkdiu9HD8TwGDwVON0es/FFRt8/J1qNjDZdMX6Cs1DOI7QCcSZ5SOA=@vger.kernel.org, AJvYcCWwamTJlf3JqwhYtNzJpNCN4iIGx2xKHUs1Mr9O+hmQw0lO7Yn6WMupPb4O6ZH357dpfHcW1Kr6J6eSbZ+1q11tfBKtCA==@vger.kernel.org X-Gm-Message-State: AOJu0YxHN5AEnYVKW7PHFZOVPsHPi3/ykeGzAylEXomSGeLftO0zrskO IYGBFgHFVywKdgP6ITyhxqT1aTB1tBvqVxSVzdxFN6ryhSRTwwiV X-Google-Smtp-Source: AGHT+IFriDItI9JE5iNNfVufzeBy/Mwq2WSUEO/UM9Bb4ULmX6zGZgRukjQkjRvw7yUqnT/Bf6KnKw== X-Received: by 2002:a05:6870:9898:b0:296:e0f7:d690 with SMTP id 586e51a60fabf-296e0f7d91fmr2139791fac.3.1732121058567; Wed, 20 Nov 2024 08:44:18 -0800 (PST) Received: from localhost.localdomain ([181.84.94.92]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7f8c1c16f36sm9752101a12.17.2024.11.20.08.44.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Nov 2024 08:44:17 -0800 (PST) From: Kurt Borja To: kuurtb@gmail.com Cc: Dell.Client.Kernel@dell.com, hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org, mario.limonciello@amd.com, platform-driver-x86@vger.kernel.org, w_armin@gmx.de Subject: [PATCH v2 4/4] alienware-wmi: Remove unnecessary check at module exit Date: Wed, 20 Nov 2024 13:44:11 -0300 Message-ID: <20241120164411.7471-1-kuurtb@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241120163834.6446-3-kuurtb@gmail.com> References: <20241120163834.6446-3-kuurtb@gmail.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Module initialization fails if platform device fails to register so it's always not NULL at exit. Signed-off-by: Kurt Borja --- v2: - Unchanged --- drivers/platform/x86/dell/alienware-wmi.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/platform/x86/dell/alienware-wmi.c b/drivers/platform/x86/dell/alienware-wmi.c index 512f6b22585c..5e0acaf35952 100644 --- a/drivers/platform/x86/dell/alienware-wmi.c +++ b/drivers/platform/x86/dell/alienware-wmi.c @@ -1197,11 +1197,9 @@ module_init(alienware_wmi_init); static void __exit alienware_wmi_exit(void) { - if (platform_device) { - remove_thermal_profile(); - platform_device_unregister(platform_device); - platform_driver_unregister(&platform_driver); - } + remove_thermal_profile(); + platform_device_unregister(platform_device); + platform_driver_unregister(&platform_driver); } module_exit(alienware_wmi_exit);