Skip to content

Commit 7a89d7e

Browse files
committed
powercap/drivers/dtpm: Simplify the dtpm table
The dtpm table is an array of pointers, that forces the user of the table to define initdata along with the declaration of the table entry. It is more efficient to create an array of dtpm structure, so the declaration of the table entry can be done by initializing the different fields. Signed-off-by: Daniel Lezcano <[email protected]> Reviewed-by: Lukasz Luba <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 4570ddd commit 7a89d7e

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

drivers/powercap/dtpm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ int dtpm_register(const char *name, struct dtpm *dtpm, struct dtpm *parent)
467467

468468
static int __init dtpm_init(void)
469469
{
470-
struct dtpm_descr **dtpm_descr;
470+
struct dtpm_descr *dtpm_descr;
471471

472472
pct = powercap_register_control_type(NULL, "dtpm", NULL);
473473
if (IS_ERR(pct)) {
@@ -476,7 +476,7 @@ static int __init dtpm_init(void)
476476
}
477477

478478
for_each_dtpm_table(dtpm_descr)
479-
(*dtpm_descr)->init(*dtpm_descr);
479+
dtpm_descr->init();
480480

481481
return 0;
482482
}

drivers/powercap/dtpm_cpu.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ static int cpuhp_dtpm_cpu_online(unsigned int cpu)
204204
return ret;
205205
}
206206

207-
int dtpm_register_cpu(struct dtpm *parent)
207+
static int __init dtpm_cpu_init(void)
208208
{
209209
int ret;
210210

@@ -241,3 +241,5 @@ int dtpm_register_cpu(struct dtpm *parent)
241241

242242
return 0;
243243
}
244+
245+
DTPM_DECLARE(dtpm_cpu, dtpm_cpu_init);

include/linux/dtpm.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,23 @@ struct dtpm_ops {
3333
void (*release)(struct dtpm *);
3434
};
3535

36-
struct dtpm_descr;
37-
38-
typedef int (*dtpm_init_t)(struct dtpm_descr *);
36+
typedef int (*dtpm_init_t)(void);
3937

4038
struct dtpm_descr {
41-
struct dtpm *parent;
42-
const char *name;
4339
dtpm_init_t init;
4440
};
4541

4642
/* Init section thermal table */
47-
extern struct dtpm_descr *__dtpm_table[];
48-
extern struct dtpm_descr *__dtpm_table_end[];
43+
extern struct dtpm_descr __dtpm_table[];
44+
extern struct dtpm_descr __dtpm_table_end[];
4945

50-
#define DTPM_TABLE_ENTRY(name) \
51-
static typeof(name) *__dtpm_table_entry_##name \
52-
__used __section("__dtpm_table") = &name
46+
#define DTPM_TABLE_ENTRY(name, __init) \
47+
static struct dtpm_descr __dtpm_table_entry_##name \
48+
__used __section("__dtpm_table") = { \
49+
.init = __init, \
50+
}
5351

54-
#define DTPM_DECLARE(name) DTPM_TABLE_ENTRY(name)
52+
#define DTPM_DECLARE(name, init) DTPM_TABLE_ENTRY(name, init)
5553

5654
#define for_each_dtpm_table(__dtpm) \
5755
for (__dtpm = __dtpm_table; \

0 commit comments

Comments
 (0)