Skip to content

Commit 99a1ae2

Browse files
nathanchancebebarino
authored andcommitted
clk: bcm2835: Remove casting to bcm2835_clk_register
There are four different callback functions that are used for the clk_register callback that all have different second parameter types. bcm2835_register_pll -> struct bcm2835_pll_data bcm2835_register_pll_divider -> struct bcm2835_pll_divider_data bcm2835_register_clock -> struct bcm2835_clock_data bcm2835_register_date -> struct bcm2835_gate_data These callbacks are cast to bcm2835_clk_register so that there is no error about incompatible pointer types. Unfortunately, this is a control flow integrity violation, which verifies that the callback function's types match the prototypes exactly before jumping. [ 0.857913] CFI failure (target: 0xffffff9334a81820): [ 0.857977] WARNING: CPU: 3 PID: 35 at kernel/cfi.c:29 __cfi_check_fail+0x50/0x58 [ 0.857985] Modules linked in: [ 0.858007] CPU: 3 PID: 35 Comm: kworker/3:1 Not tainted 4.19.123-v8-01301-gdbb48f16956e4-dirty #1 [ 0.858015] Hardware name: Raspberry Pi 3 Model B Rev 1.2 (DT) [ 0.858031] Workqueue: events 0xffffff9334a925c8 [ 0.858046] pstate: 60000005 (nZCv daif -PAN -UAO) [ 0.858058] pc : __cfi_check_fail+0x50/0x58 [ 0.858070] lr : __cfi_check_fail+0x50/0x58 [ 0.858078] sp : ffffff800814ba90 [ 0.858086] x29: ffffff800814ba90 x28: 000fffffffdfff3d [ 0.858101] x27: 00000000002000c2 x26: ffffff93355fdb18 [ 0.858116] x25: 0000000000000000 x24: ffffff9334a81820 [ 0.858131] x23: ffffff93357f3580 x22: ffffff9334af1000 [ 0.858146] x21: a79b57e88f8ebc81 x20: ffffff93357f3580 [ 0.858161] x19: ffffff9334a81820 x18: fffffff679769070 [ 0.858175] x17: 0000000000000000 x16: 0000000000000000 [ 0.858190] x15: 0000000000000004 x14: 000000000000003c [ 0.858205] x13: 0000000000003044 x12: 0000000000000000 [ 0.858220] x11: b57e91cd641bae00 x10: b57e91cd641bae00 [ 0.858235] x9 : b57e91cd641bae00 x8 : b57e91cd641bae00 [ 0.858250] x7 : 0000000000000000 x6 : ffffff933591d4e5 [ 0.858264] x5 : 0000000000000000 x4 : 0000000000000000 [ 0.858279] x3 : ffffff800814b718 x2 : ffffff9334a84818 [ 0.858293] x1 : ffffff9334bba66c x0 : 0000000000000029 [ 0.858308] Call trace: [ 0.858321] __cfi_check_fail+0x50/0x58 [ 0.858337] __cfi_check+0x3ab3c/0x4467c [ 0.858351] bcm2835_clk_probe+0x210/0x2dc [ 0.858369] platform_drv_probe+0xb0/0xfc [ 0.858380] really_probe+0x4a0/0x5a8 [ 0.858391] driver_probe_device+0x68/0x104 [ 0.858403] __device_attach_driver+0x100/0x148 [ 0.858418] bus_for_each_drv+0xb0/0x12c [ 0.858431] __device_attach.llvm.17225159516306086099+0xc0/0x168 [ 0.858443] bus_probe_device+0x44/0xfc [ 0.858455] deferred_probe_work_func+0xa0/0xe0 [ 0.858472] process_one_work+0x210/0x538 [ 0.858485] worker_thread+0x2e8/0x478 [ 0.858500] kthread+0x154/0x164 [ 0.858515] ret_from_fork+0x10/0x18 To fix this, change the second parameter of all functions void * and use a local variable with the correct type so that everything works properly. With this, the only use of bcm2835_clk_register is in struct bcm2835_clk_desc so we can just remove it and use the type directly. Fixes: 56eb3a2 ("clk: bcm2835: remove use of BCM2835_CLOCK_COUNT in driver") Link: ClangBuiltLinux#1028 Signed-off-by: Nathan Chancellor <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent f376c43 commit 99a1ae2

File tree

1 file changed

+37
-31
lines changed

1 file changed

+37
-31
lines changed

drivers/clk/bcm/clk-bcm2835.c

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,8 +1296,9 @@ static const struct clk_ops bcm2835_vpu_clock_clk_ops = {
12961296
};
12971297

12981298
static struct clk_hw *bcm2835_register_pll(struct bcm2835_cprman *cprman,
1299-
const struct bcm2835_pll_data *data)
1299+
const void *data)
13001300
{
1301+
const struct bcm2835_pll_data *pll_data = data;
13011302
struct bcm2835_pll *pll;
13021303
struct clk_init_data init;
13031304
int ret;
@@ -1307,7 +1308,7 @@ static struct clk_hw *bcm2835_register_pll(struct bcm2835_cprman *cprman,
13071308
/* All of the PLLs derive from the external oscillator. */
13081309
init.parent_names = &cprman->real_parent_names[0];
13091310
init.num_parents = 1;
1310-
init.name = data->name;
1311+
init.name = pll_data->name;
13111312
init.ops = &bcm2835_pll_clk_ops;
13121313
init.flags = CLK_IGNORE_UNUSED;
13131314

@@ -1316,7 +1317,7 @@ static struct clk_hw *bcm2835_register_pll(struct bcm2835_cprman *cprman,
13161317
return NULL;
13171318

13181319
pll->cprman = cprman;
1319-
pll->data = data;
1320+
pll->data = pll_data;
13201321
pll->hw.init = &init;
13211322

13221323
ret = devm_clk_hw_register(cprman->dev, &pll->hw);
@@ -1327,35 +1328,36 @@ static struct clk_hw *bcm2835_register_pll(struct bcm2835_cprman *cprman,
13271328

13281329
static struct clk_hw *
13291330
bcm2835_register_pll_divider(struct bcm2835_cprman *cprman,
1330-
const struct bcm2835_pll_divider_data *data)
1331+
const void *data)
13311332
{
1333+
const struct bcm2835_pll_divider_data *divider_data = data;
13321334
struct bcm2835_pll_divider *divider;
13331335
struct clk_init_data init;
13341336
const char *divider_name;
13351337
int ret;
13361338

1337-
if (data->fixed_divider != 1) {
1339+
if (divider_data->fixed_divider != 1) {
13381340
divider_name = devm_kasprintf(cprman->dev, GFP_KERNEL,
1339-
"%s_prediv", data->name);
1341+
"%s_prediv", divider_data->name);
13401342
if (!divider_name)
13411343
return NULL;
13421344
} else {
1343-
divider_name = data->name;
1345+
divider_name = divider_data->name;
13441346
}
13451347

13461348
memset(&init, 0, sizeof(init));
13471349

1348-
init.parent_names = &data->source_pll;
1350+
init.parent_names = &divider_data->source_pll;
13491351
init.num_parents = 1;
13501352
init.name = divider_name;
13511353
init.ops = &bcm2835_pll_divider_clk_ops;
1352-
init.flags = data->flags | CLK_IGNORE_UNUSED;
1354+
init.flags = divider_data->flags | CLK_IGNORE_UNUSED;
13531355

13541356
divider = devm_kzalloc(cprman->dev, sizeof(*divider), GFP_KERNEL);
13551357
if (!divider)
13561358
return NULL;
13571359

1358-
divider->div.reg = cprman->regs + data->a2w_reg;
1360+
divider->div.reg = cprman->regs + divider_data->a2w_reg;
13591361
divider->div.shift = A2W_PLL_DIV_SHIFT;
13601362
divider->div.width = A2W_PLL_DIV_BITS;
13611363
divider->div.flags = CLK_DIVIDER_MAX_AT_ZERO;
@@ -1364,7 +1366,7 @@ bcm2835_register_pll_divider(struct bcm2835_cprman *cprman,
13641366
divider->div.table = NULL;
13651367

13661368
divider->cprman = cprman;
1367-
divider->data = data;
1369+
divider->data = divider_data;
13681370

13691371
ret = devm_clk_hw_register(cprman->dev, &divider->div.hw);
13701372
if (ret)
@@ -1374,20 +1376,22 @@ bcm2835_register_pll_divider(struct bcm2835_cprman *cprman,
13741376
* PLLH's channels have a fixed divide by 10 afterwards, which
13751377
* is what our consumers are actually using.
13761378
*/
1377-
if (data->fixed_divider != 1) {
1378-
return clk_hw_register_fixed_factor(cprman->dev, data->name,
1379+
if (divider_data->fixed_divider != 1) {
1380+
return clk_hw_register_fixed_factor(cprman->dev,
1381+
divider_data->name,
13791382
divider_name,
13801383
CLK_SET_RATE_PARENT,
13811384
1,
1382-
data->fixed_divider);
1385+
divider_data->fixed_divider);
13831386
}
13841387

13851388
return &divider->div.hw;
13861389
}
13871390

13881391
static struct clk_hw *bcm2835_register_clock(struct bcm2835_cprman *cprman,
1389-
const struct bcm2835_clock_data *data)
1392+
const void *data)
13901393
{
1394+
const struct bcm2835_clock_data *clock_data = data;
13911395
struct bcm2835_clock *clock;
13921396
struct clk_init_data init;
13931397
const char *parents[1 << CM_SRC_BITS];
@@ -1398,8 +1402,8 @@ static struct clk_hw *bcm2835_register_clock(struct bcm2835_cprman *cprman,
13981402
* Replace our strings referencing parent clocks with the
13991403
* actual clock-output-name of the parent.
14001404
*/
1401-
for (i = 0; i < data->num_mux_parents; i++) {
1402-
parents[i] = data->parents[i];
1405+
for (i = 0; i < clock_data->num_mux_parents; i++) {
1406+
parents[i] = clock_data->parents[i];
14031407

14041408
ret = match_string(cprman_parent_names,
14051409
ARRAY_SIZE(cprman_parent_names),
@@ -1410,18 +1414,18 @@ static struct clk_hw *bcm2835_register_clock(struct bcm2835_cprman *cprman,
14101414

14111415
memset(&init, 0, sizeof(init));
14121416
init.parent_names = parents;
1413-
init.num_parents = data->num_mux_parents;
1414-
init.name = data->name;
1415-
init.flags = data->flags | CLK_IGNORE_UNUSED;
1417+
init.num_parents = clock_data->num_mux_parents;
1418+
init.name = clock_data->name;
1419+
init.flags = clock_data->flags | CLK_IGNORE_UNUSED;
14161420

14171421
/*
14181422
* Pass the CLK_SET_RATE_PARENT flag if we are allowed to propagate
14191423
* rate changes on at least of the parents.
14201424
*/
1421-
if (data->set_rate_parent)
1425+
if (clock_data->set_rate_parent)
14221426
init.flags |= CLK_SET_RATE_PARENT;
14231427

1424-
if (data->is_vpu_clock) {
1428+
if (clock_data->is_vpu_clock) {
14251429
init.ops = &bcm2835_vpu_clock_clk_ops;
14261430
} else {
14271431
init.ops = &bcm2835_clock_clk_ops;
@@ -1430,7 +1434,7 @@ static struct clk_hw *bcm2835_register_clock(struct bcm2835_cprman *cprman,
14301434
/* If the clock wasn't actually enabled at boot, it's not
14311435
* critical.
14321436
*/
1433-
if (!(cprman_read(cprman, data->ctl_reg) & CM_ENABLE))
1437+
if (!(cprman_read(cprman, clock_data->ctl_reg) & CM_ENABLE))
14341438
init.flags &= ~CLK_IS_CRITICAL;
14351439
}
14361440

@@ -1439,7 +1443,7 @@ static struct clk_hw *bcm2835_register_clock(struct bcm2835_cprman *cprman,
14391443
return NULL;
14401444

14411445
clock->cprman = cprman;
1442-
clock->data = data;
1446+
clock->data = clock_data;
14431447
clock->hw.init = &init;
14441448

14451449
ret = devm_clk_hw_register(cprman->dev, &clock->hw);
@@ -1449,24 +1453,26 @@ static struct clk_hw *bcm2835_register_clock(struct bcm2835_cprman *cprman,
14491453
}
14501454

14511455
static struct clk_hw *bcm2835_register_gate(struct bcm2835_cprman *cprman,
1452-
const struct bcm2835_gate_data *data)
1456+
const void *data)
14531457
{
1454-
return clk_hw_register_gate(cprman->dev, data->name, data->parent,
1458+
const struct bcm2835_gate_data *gate_data = data;
1459+
1460+
return clk_hw_register_gate(cprman->dev, gate_data->name,
1461+
gate_data->parent,
14551462
CLK_IGNORE_UNUSED | CLK_SET_RATE_GATE,
1456-
cprman->regs + data->ctl_reg,
1463+
cprman->regs + gate_data->ctl_reg,
14571464
CM_GATE_BIT, 0, &cprman->regs_lock);
14581465
}
14591466

1460-
typedef struct clk_hw *(*bcm2835_clk_register)(struct bcm2835_cprman *cprman,
1461-
const void *data);
14621467
struct bcm2835_clk_desc {
1463-
bcm2835_clk_register clk_register;
1468+
struct clk_hw *(*clk_register)(struct bcm2835_cprman *cprman,
1469+
const void *data);
14641470
unsigned int supported;
14651471
const void *data;
14661472
};
14671473

14681474
/* assignment helper macros for different clock types */
1469-
#define _REGISTER(f, s, ...) { .clk_register = (bcm2835_clk_register)f, \
1475+
#define _REGISTER(f, s, ...) { .clk_register = f, \
14701476
.supported = s, \
14711477
.data = __VA_ARGS__ }
14721478
#define REGISTER_PLL(s, ...) _REGISTER(&bcm2835_register_pll, \

0 commit comments

Comments
 (0)