mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-28 11:18:45 +07:00
b08fc5277a
- Additional struct_size() conversions (Matthew, Kees) - Explicitly reported overflow fixes (Silvio, Kees) - Add missing kvcalloc() function (Kees) - Treewide conversions of allocators to use either 2-factor argument variant when available, or array_size() and array3_size() as needed (Kees) -----BEGIN PGP SIGNATURE----- Comment: Kees Cook <kees@outflux.net> iQJKBAABCgA0FiEEpcP2jyKd1g9yPm4TiXL039xtwCYFAlsgVtMWHGtlZXNjb29r QGNocm9taXVtLm9yZwAKCRCJcvTf3G3AJhsJEACLYe2EbwLFJz7emOT1KUGK5R1b oVxJog0893WyMqgk9XBlA2lvTBRBYzR3tzsadfYo87L3VOBzazUv0YZaweJb65sF bAvxW3nY06brhKKwTRed1PrMa1iG9R63WISnNAuZAq7+79mN6YgW4G6YSAEF9lW7 oPJoPw93YxcI8JcG+dA8BC9w7pJFKooZH4gvLUSUNl5XKr8Ru5YnWcV8F+8M4vZI EJtXFmdlmxAledUPxTSCIojO8m/tNOjYTreBJt9K1DXKY6UcgAdhk75TRLEsp38P fPvMigYQpBDnYz2pi9ourTgvZLkffK1OBZ46PPt8BgUZVf70D6CBg10vK47KO6N2 zreloxkMTrz5XohyjfNjYFRkyyuwV2sSVrRJqF4dpyJ4NJQRjvyywxIP4Myifwlb ONipCM1EjvQjaEUbdcqKgvlooMdhcyxfshqJWjHzXB6BL22uPzq5jHXXugz8/ol8 tOSM2FuJ2sBLQso+szhisxtMd11PihzIZK9BfxEG3du+/hlI+2XgN7hnmlXuA2k3 BUW6BSDhab41HNd6pp50bDJnL0uKPWyFC6hqSNZw+GOIb46jfFcQqnCB3VZGCwj3 LH53Be1XlUrttc/NrtkvVhm4bdxtfsp4F7nsPFNDuHvYNkalAVoC3An0BzOibtkh AtfvEeaPHaOyD8/h2Q== =zUUp -----END PGP SIGNATURE----- Merge tag 'overflow-v4.18-rc1-part2' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux Pull more overflow updates from Kees Cook: "The rest of the overflow changes for v4.18-rc1. This includes the explicit overflow fixes from Silvio, further struct_size() conversions from Matthew, and a bug fix from Dan. But the bulk of it is the treewide conversions to use either the 2-factor argument allocators (e.g. kmalloc(a * b, ...) into kmalloc_array(a, b, ...) or the array_size() macros (e.g. vmalloc(a * b) into vmalloc(array_size(a, b)). Coccinelle was fighting me on several fronts, so I've done a bunch of manual whitespace updates in the patches as well. Summary: - Error path bug fix for overflow tests (Dan) - Additional struct_size() conversions (Matthew, Kees) - Explicitly reported overflow fixes (Silvio, Kees) - Add missing kvcalloc() function (Kees) - Treewide conversions of allocators to use either 2-factor argument variant when available, or array_size() and array3_size() as needed (Kees)" * tag 'overflow-v4.18-rc1-part2' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: (26 commits) treewide: Use array_size in f2fs_kvzalloc() treewide: Use array_size() in f2fs_kzalloc() treewide: Use array_size() in f2fs_kmalloc() treewide: Use array_size() in sock_kmalloc() treewide: Use array_size() in kvzalloc_node() treewide: Use array_size() in vzalloc_node() treewide: Use array_size() in vzalloc() treewide: Use array_size() in vmalloc() treewide: devm_kzalloc() -> devm_kcalloc() treewide: devm_kmalloc() -> devm_kmalloc_array() treewide: kvzalloc() -> kvcalloc() treewide: kvmalloc() -> kvmalloc_array() treewide: kzalloc_node() -> kcalloc_node() treewide: kzalloc() -> kcalloc() treewide: kmalloc() -> kmalloc_array() mm: Introduce kvcalloc() video: uvesafb: Fix integer overflow in allocation UBIFS: Fix potential integer overflow in allocation leds: Use struct_size() in allocation Convert intel uncore to struct_size ...
296 lines
7.9 KiB
C
296 lines
7.9 KiB
C
/*
|
|
* int340x_thermal_zone.c
|
|
* Copyright (c) 2015, Intel Corporation.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms and conditions of the GNU General Public License,
|
|
* version 2, as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
*/
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/init.h>
|
|
#include <linux/acpi.h>
|
|
#include <linux/thermal.h>
|
|
#include "int340x_thermal_zone.h"
|
|
|
|
static int int340x_thermal_get_zone_temp(struct thermal_zone_device *zone,
|
|
int *temp)
|
|
{
|
|
struct int34x_thermal_zone *d = zone->devdata;
|
|
unsigned long long tmp;
|
|
acpi_status status;
|
|
|
|
if (d->override_ops && d->override_ops->get_temp)
|
|
return d->override_ops->get_temp(zone, temp);
|
|
|
|
status = acpi_evaluate_integer(d->adev->handle, "_TMP", NULL, &tmp);
|
|
if (ACPI_FAILURE(status))
|
|
return -EIO;
|
|
|
|
if (d->lpat_table) {
|
|
int conv_temp;
|
|
|
|
conv_temp = acpi_lpat_raw_to_temp(d->lpat_table, (int)tmp);
|
|
if (conv_temp < 0)
|
|
return conv_temp;
|
|
|
|
*temp = (unsigned long)conv_temp * 10;
|
|
} else
|
|
/* _TMP returns the temperature in tenths of degrees Kelvin */
|
|
*temp = DECI_KELVIN_TO_MILLICELSIUS(tmp);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int int340x_thermal_get_trip_temp(struct thermal_zone_device *zone,
|
|
int trip, int *temp)
|
|
{
|
|
struct int34x_thermal_zone *d = zone->devdata;
|
|
int i;
|
|
|
|
if (d->override_ops && d->override_ops->get_trip_temp)
|
|
return d->override_ops->get_trip_temp(zone, trip, temp);
|
|
|
|
if (trip < d->aux_trip_nr)
|
|
*temp = d->aux_trips[trip];
|
|
else if (trip == d->crt_trip_id)
|
|
*temp = d->crt_temp;
|
|
else if (trip == d->psv_trip_id)
|
|
*temp = d->psv_temp;
|
|
else if (trip == d->hot_trip_id)
|
|
*temp = d->hot_temp;
|
|
else {
|
|
for (i = 0; i < INT340X_THERMAL_MAX_ACT_TRIP_COUNT; i++) {
|
|
if (d->act_trips[i].valid &&
|
|
d->act_trips[i].id == trip) {
|
|
*temp = d->act_trips[i].temp;
|
|
break;
|
|
}
|
|
}
|
|
if (i == INT340X_THERMAL_MAX_ACT_TRIP_COUNT)
|
|
return -EINVAL;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int int340x_thermal_get_trip_type(struct thermal_zone_device *zone,
|
|
int trip,
|
|
enum thermal_trip_type *type)
|
|
{
|
|
struct int34x_thermal_zone *d = zone->devdata;
|
|
int i;
|
|
|
|
if (d->override_ops && d->override_ops->get_trip_type)
|
|
return d->override_ops->get_trip_type(zone, trip, type);
|
|
|
|
if (trip < d->aux_trip_nr)
|
|
*type = THERMAL_TRIP_PASSIVE;
|
|
else if (trip == d->crt_trip_id)
|
|
*type = THERMAL_TRIP_CRITICAL;
|
|
else if (trip == d->hot_trip_id)
|
|
*type = THERMAL_TRIP_HOT;
|
|
else if (trip == d->psv_trip_id)
|
|
*type = THERMAL_TRIP_PASSIVE;
|
|
else {
|
|
for (i = 0; i < INT340X_THERMAL_MAX_ACT_TRIP_COUNT; i++) {
|
|
if (d->act_trips[i].valid &&
|
|
d->act_trips[i].id == trip) {
|
|
*type = THERMAL_TRIP_ACTIVE;
|
|
break;
|
|
}
|
|
}
|
|
if (i == INT340X_THERMAL_MAX_ACT_TRIP_COUNT)
|
|
return -EINVAL;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int int340x_thermal_set_trip_temp(struct thermal_zone_device *zone,
|
|
int trip, int temp)
|
|
{
|
|
struct int34x_thermal_zone *d = zone->devdata;
|
|
acpi_status status;
|
|
char name[10];
|
|
|
|
if (d->override_ops && d->override_ops->set_trip_temp)
|
|
return d->override_ops->set_trip_temp(zone, trip, temp);
|
|
|
|
snprintf(name, sizeof(name), "PAT%d", trip);
|
|
status = acpi_execute_simple_method(d->adev->handle, name,
|
|
MILLICELSIUS_TO_DECI_KELVIN(temp));
|
|
if (ACPI_FAILURE(status))
|
|
return -EIO;
|
|
|
|
d->aux_trips[trip] = temp;
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
static int int340x_thermal_get_trip_hyst(struct thermal_zone_device *zone,
|
|
int trip, int *temp)
|
|
{
|
|
struct int34x_thermal_zone *d = zone->devdata;
|
|
acpi_status status;
|
|
unsigned long long hyst;
|
|
|
|
if (d->override_ops && d->override_ops->get_trip_hyst)
|
|
return d->override_ops->get_trip_hyst(zone, trip, temp);
|
|
|
|
status = acpi_evaluate_integer(d->adev->handle, "GTSH", NULL, &hyst);
|
|
if (ACPI_FAILURE(status))
|
|
*temp = 0;
|
|
else
|
|
*temp = hyst * 100;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct thermal_zone_device_ops int340x_thermal_zone_ops = {
|
|
.get_temp = int340x_thermal_get_zone_temp,
|
|
.get_trip_temp = int340x_thermal_get_trip_temp,
|
|
.get_trip_type = int340x_thermal_get_trip_type,
|
|
.set_trip_temp = int340x_thermal_set_trip_temp,
|
|
.get_trip_hyst = int340x_thermal_get_trip_hyst,
|
|
};
|
|
|
|
static int int340x_thermal_get_trip_config(acpi_handle handle, char *name,
|
|
int *temp)
|
|
{
|
|
unsigned long long r;
|
|
acpi_status status;
|
|
|
|
status = acpi_evaluate_integer(handle, name, NULL, &r);
|
|
if (ACPI_FAILURE(status))
|
|
return -EIO;
|
|
|
|
*temp = DECI_KELVIN_TO_MILLICELSIUS(r);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int int340x_thermal_read_trips(struct int34x_thermal_zone *int34x_zone)
|
|
{
|
|
int trip_cnt = int34x_zone->aux_trip_nr;
|
|
int i;
|
|
|
|
int34x_zone->crt_trip_id = -1;
|
|
if (!int340x_thermal_get_trip_config(int34x_zone->adev->handle, "_CRT",
|
|
&int34x_zone->crt_temp))
|
|
int34x_zone->crt_trip_id = trip_cnt++;
|
|
|
|
int34x_zone->hot_trip_id = -1;
|
|
if (!int340x_thermal_get_trip_config(int34x_zone->adev->handle, "_HOT",
|
|
&int34x_zone->hot_temp))
|
|
int34x_zone->hot_trip_id = trip_cnt++;
|
|
|
|
int34x_zone->psv_trip_id = -1;
|
|
if (!int340x_thermal_get_trip_config(int34x_zone->adev->handle, "_PSV",
|
|
&int34x_zone->psv_temp))
|
|
int34x_zone->psv_trip_id = trip_cnt++;
|
|
|
|
for (i = 0; i < INT340X_THERMAL_MAX_ACT_TRIP_COUNT; i++) {
|
|
char name[5] = { '_', 'A', 'C', '0' + i, '\0' };
|
|
|
|
if (int340x_thermal_get_trip_config(int34x_zone->adev->handle,
|
|
name,
|
|
&int34x_zone->act_trips[i].temp))
|
|
break;
|
|
|
|
int34x_zone->act_trips[i].id = trip_cnt++;
|
|
int34x_zone->act_trips[i].valid = true;
|
|
}
|
|
|
|
return trip_cnt;
|
|
}
|
|
EXPORT_SYMBOL_GPL(int340x_thermal_read_trips);
|
|
|
|
static struct thermal_zone_params int340x_thermal_params = {
|
|
.governor_name = "user_space",
|
|
.no_hwmon = true,
|
|
};
|
|
|
|
struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
|
|
struct thermal_zone_device_ops *override_ops)
|
|
{
|
|
struct int34x_thermal_zone *int34x_thermal_zone;
|
|
acpi_status status;
|
|
unsigned long long trip_cnt;
|
|
int trip_mask = 0;
|
|
int ret;
|
|
|
|
int34x_thermal_zone = kzalloc(sizeof(*int34x_thermal_zone),
|
|
GFP_KERNEL);
|
|
if (!int34x_thermal_zone)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
int34x_thermal_zone->adev = adev;
|
|
int34x_thermal_zone->override_ops = override_ops;
|
|
|
|
status = acpi_evaluate_integer(adev->handle, "PATC", NULL, &trip_cnt);
|
|
if (ACPI_FAILURE(status))
|
|
trip_cnt = 0;
|
|
else {
|
|
int34x_thermal_zone->aux_trips =
|
|
kcalloc(trip_cnt,
|
|
sizeof(*int34x_thermal_zone->aux_trips),
|
|
GFP_KERNEL);
|
|
if (!int34x_thermal_zone->aux_trips) {
|
|
ret = -ENOMEM;
|
|
goto err_trip_alloc;
|
|
}
|
|
trip_mask = BIT(trip_cnt) - 1;
|
|
int34x_thermal_zone->aux_trip_nr = trip_cnt;
|
|
}
|
|
|
|
trip_cnt = int340x_thermal_read_trips(int34x_thermal_zone);
|
|
|
|
int34x_thermal_zone->lpat_table = acpi_lpat_get_conversion_table(
|
|
adev->handle);
|
|
|
|
int34x_thermal_zone->zone = thermal_zone_device_register(
|
|
acpi_device_bid(adev),
|
|
trip_cnt,
|
|
trip_mask, int34x_thermal_zone,
|
|
&int340x_thermal_zone_ops,
|
|
&int340x_thermal_params,
|
|
0, 0);
|
|
if (IS_ERR(int34x_thermal_zone->zone)) {
|
|
ret = PTR_ERR(int34x_thermal_zone->zone);
|
|
goto err_thermal_zone;
|
|
}
|
|
|
|
return int34x_thermal_zone;
|
|
|
|
err_thermal_zone:
|
|
acpi_lpat_free_conversion_table(int34x_thermal_zone->lpat_table);
|
|
kfree(int34x_thermal_zone->aux_trips);
|
|
err_trip_alloc:
|
|
kfree(int34x_thermal_zone);
|
|
return ERR_PTR(ret);
|
|
}
|
|
EXPORT_SYMBOL_GPL(int340x_thermal_zone_add);
|
|
|
|
void int340x_thermal_zone_remove(struct int34x_thermal_zone
|
|
*int34x_thermal_zone)
|
|
{
|
|
thermal_zone_device_unregister(int34x_thermal_zone->zone);
|
|
acpi_lpat_free_conversion_table(int34x_thermal_zone->lpat_table);
|
|
kfree(int34x_thermal_zone->aux_trips);
|
|
kfree(int34x_thermal_zone);
|
|
}
|
|
EXPORT_SYMBOL_GPL(int340x_thermal_zone_remove);
|
|
|
|
MODULE_AUTHOR("Aaron Lu <aaron.lu@intel.com>");
|
|
MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
|
|
MODULE_DESCRIPTION("Intel INT340x common thermal zone handler");
|
|
MODULE_LICENSE("GPL v2");
|