tools/lib/thermal/thermal.c

Source file repositories/reference/linux-study-clean/tools/lib/thermal/thermal.c

File Facts

System
Linux kernel
Corpus path
tools/lib/thermal/thermal.c
Extension
.c
Size
2478 bytes
Lines
153
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: LGPL-2.1+
// Copyright (C) 2022, Linaro Ltd - Daniel Lezcano <daniel.lezcano@linaro.org>
#include <stdio.h>
#include <limits.h>
#include <thermal.h>

#include "thermal_nl.h"

int for_each_thermal_threshold(struct thermal_threshold *th, cb_th_t cb, void *arg)
{
	int i, ret = 0;

	if (!th)
		return 0;

	for (i = 0; th[i].temperature != INT_MAX; i++)
		ret |= cb(&th[i], arg);

	return ret;
}

int for_each_thermal_cdev(struct thermal_cdev *cdev, cb_tc_t cb, void *arg)
{
	int i, ret = 0;

	if (!cdev)
		return 0;

	for (i = 0; cdev[i].id != -1; i++)
		ret |= cb(&cdev[i], arg);

	return ret;
}

int for_each_thermal_trip(struct thermal_trip *tt, cb_tt_t cb, void *arg)
{
	int i, ret = 0;

	if (!tt)
		return 0;

	for (i = 0; tt[i].id != -1; i++)
		ret |= cb(&tt[i], arg);

	return ret;
}

int for_each_thermal_zone(struct thermal_zone *tz, cb_tz_t cb, void *arg)
{
	int i, ret = 0;

	if (!tz)
		return 0;

	for (i = 0; tz[i].id != -1; i++)
		ret |= cb(&tz[i], arg);

	return ret;
}

struct thermal_zone *thermal_zone_find_by_name(struct thermal_zone *tz,
					       const char *name)
{
	int i;

	if (!tz || !name)
		return NULL;

	for (i = 0; tz[i].id != -1; i++) {
		if (!strcmp(tz[i].name, name))
			return &tz[i];
	}

	return NULL;
}

struct thermal_zone *thermal_zone_find_by_id(struct thermal_zone *tz, int id)
{
	int i;

	if (!tz || id < 0)
		return NULL;

	for (i = 0; tz[i].id != -1; i++) {
		if (tz[i].id == id)
			return &tz[i];
	}

	return NULL;
}

Annotation

Implementation Notes