Merge tag 'x86-urgent-2025-01-28' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-stable.git] / drivers / thermal / gov_user_space.c
blobef95cf7d65efbef8282a183d470117da31b1b589
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * user_space.c - A simple user space Thermal events notifier
5 * Copyright (C) 2012 Intel Corp
6 * Copyright (C) 2012 Durgadoss R <durgadoss.r@intel.com>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13 #include <linux/slab.h>
14 #include <linux/thermal.h>
16 #include "thermal_core.h"
18 static int user_space_bind(struct thermal_zone_device *tz)
20 pr_info_once("Consider using thermal netlink events interface\n");
22 return 0;
25 /**
26 * user_space_trip_crossed - Notify user space about trip crossing events
27 * @tz: thermal_zone_device
28 * @trip: trip point
29 * @upward: whether or not the trip has been crossed on the way up
31 * This function notifies the user space through UEvents.
33 static void user_space_trip_crossed(struct thermal_zone_device *tz,
34 const struct thermal_trip *trip,
35 bool upward)
37 char *thermal_prop[5];
38 int i;
40 lockdep_assert_held(&tz->lock);
42 thermal_prop[0] = kasprintf(GFP_KERNEL, "NAME=%s", tz->type);
43 thermal_prop[1] = kasprintf(GFP_KERNEL, "TEMP=%d", tz->temperature);
44 thermal_prop[2] = kasprintf(GFP_KERNEL, "TRIP=%d",
45 thermal_zone_trip_id(tz, trip));
46 thermal_prop[3] = kasprintf(GFP_KERNEL, "EVENT=%d", tz->notify_event);
47 thermal_prop[4] = NULL;
48 kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, thermal_prop);
49 for (i = 0; i < 4; ++i)
50 kfree(thermal_prop[i]);
53 static struct thermal_governor thermal_gov_user_space = {
54 .name = "user_space",
55 .trip_crossed = user_space_trip_crossed,
56 .bind_to_tz = user_space_bind,
58 THERMAL_GOVERNOR_DECLARE(thermal_gov_user_space);