Skip to content

Commit a4dc7ff

Browse files
committed
[POWERPC] Define of_read_ulong helper
There are various places where we want to extract an unsigned long value from a device-tree property that can be 1 or 2 cells in length. This replaces some open-coded calculations, and one place where we assumed without checking that properties were the length we wanted, with a little of_read_ulong() helper. Signed-off-by: Paul Mackerras <paulus@samba.org>
1 parent 19e59df commit a4dc7ff

4 files changed

Lines changed: 22 additions & 26 deletions

File tree

‎arch/powerpc/kernel/prom.c‎

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -757,24 +757,9 @@ static int __init early_init_dt_scan_root(unsigned long node,
757757
static unsigned long __init dt_mem_next_cell(int s, cell_t **cellp)
758758
{
759759
cell_t *p = *cellp;
760-
unsigned long r;
761760

762-
/* Ignore more than 2 cells */
763-
while (s > sizeof(unsigned long) / 4) {
764-
p++;
765-
s--;
766-
}
767-
r = *p++;
768-
#ifdef CONFIG_PPC64
769-
if (s > 1) {
770-
r <<= 32;
771-
r |= *(p++);
772-
s--;
773-
}
774-
#endif
775-
776-
*cellp = p;
777-
return r;
761+
*cellp = p + s;
762+
return of_read_ulong(p, s);
778763
}
779764

780765

‎arch/powerpc/kernel/setup-common.c‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,18 +304,21 @@ struct seq_operations cpuinfo_op = {
304304
void __init check_for_initrd(void)
305305
{
306306
#ifdef CONFIG_BLK_DEV_INITRD
307-
const unsigned long *prop;
307+
const unsigned int *prop;
308+
int len;
308309

309310
DBG(" -> check_for_initrd()\n");
310311

311312
if (of_chosen) {
312-
prop = get_property(of_chosen, "linux,initrd-start", NULL);
313+
prop = get_property(of_chosen, "linux,initrd-start", &len);
313314
if (prop != NULL) {
314-
initrd_start = (unsigned long)__va(*prop);
315+
initrd_start = (unsigned long)
316+
__va(of_read_ulong(prop, len / 4));
315317
prop = get_property(of_chosen,
316-
"linux,initrd-end", NULL);
318+
"linux,initrd-end", &len);
317319
if (prop != NULL) {
318-
initrd_end = (unsigned long)__va(*prop);
320+
initrd_end = (unsigned long)
321+
__va(of_read_ulong(prop, len / 4));
319322
initrd_below_start_ok = 1;
320323
} else
321324
initrd_start = 0;

‎arch/powerpc/kernel/time.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -870,9 +870,7 @@ static int __init get_freq(char *name, int cells, unsigned long *val)
870870
fp = get_property(cpu, name, NULL);
871871
if (fp) {
872872
found = 1;
873-
*val = 0;
874-
while (cells--)
875-
*val = (*val << 32) | *fp++;
873+
*val = of_read_ulong(fp, cells);
876874
}
877875

878876
of_node_put(cpu);

‎include/asm-powerpc/prom.h‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ extern int release_OF_resource(struct device_node* node, int index);
197197
*/
198198

199199

200-
/* Helper to read a big number */
200+
/* Helper to read a big number; size is in cells (not bytes) */
201201
static inline u64 of_read_number(const u32 *cell, int size)
202202
{
203203
u64 r = 0;
@@ -206,6 +206,16 @@ static inline u64 of_read_number(const u32 *cell, int size)
206206
return r;
207207
}
208208

209+
/* Like of_read_number, but we want an unsigned long result */
210+
#ifdef CONFIG_PPC32
211+
static inline unsigned long of_read_ulong(const u32 *cell, int size)
212+
{
213+
return cell[size-1];
214+
}
215+
#else
216+
#define of_read_ulong(cell, size) of_read_number(cell, size)
217+
#endif
218+
209219
/* Translate an OF address block into a CPU physical address
210220
*/
211221
#define OF_BAD_ADDR ((u64)-1)

0 commit comments

Comments
 (0)