@@ -663,6 +663,29 @@ static inline int __init prom_getprop(phandle node, const char *pname,
663663 (u32 )(unsigned long ) value , (u32 ) valuelen );
664664}
665665
666+ static int __init prom_getprop_string (phandle node , const char * pname ,
667+ char * value , size_t valuelen )
668+ {
669+ int rc ;
670+
671+ if (!valuelen )
672+ return PROM_ERROR ;
673+
674+ rc = prom_getprop (node , pname , value , valuelen );
675+ if (rc == PROM_ERROR || rc <= 0 ) {
676+ value [0 ] = '\0' ;
677+ return rc ;
678+ }
679+
680+ if (rc >= valuelen ) {
681+ value [valuelen - 1 ] = '\0' ;
682+ return PROM_ERROR ;
683+ }
684+ value [rc ] = '\0' ;
685+
686+ return rc ;
687+ }
688+
666689static inline int __init prom_getproplen (phandle node , const char * pname )
667690{
668691 return call_prom ("getproplen" , 2 , 1 , node , ADDR (pname ));
@@ -791,7 +814,8 @@ static void __init early_cmdline_parse(void)
791814 p = prom_cmd_line ;
792815
793816 if (!IS_ENABLED (CONFIG_CMDLINE_FORCE ) && (long )prom .chosen > 0 )
794- l = prom_getprop (prom .chosen , "bootargs" , p , COMMAND_LINE_SIZE - 1 );
817+ l = prom_getprop_string (prom .chosen , "bootargs" , p ,
818+ COMMAND_LINE_SIZE );
795819
796820 if (IS_ENABLED (CONFIG_CMDLINE_EXTEND ) || l <= 0 || p [0 ] == '\0' )
797821 prom_strlcat (prom_cmd_line , " " CONFIG_CMDLINE ,
@@ -1231,7 +1255,7 @@ static int __init prom_count_smt_threads(void)
12311255 /* Pick up th first CPU node we can find */
12321256 for (node = 0 ; prom_next_node (& node ); ) {
12331257 type [0 ] = 0 ;
1234- prom_getprop (node , "device_type" , type , sizeof (type ));
1258+ prom_getprop_string (node , "device_type" , type , sizeof (type ));
12351259
12361260 if (prom_strcmp (type , "cpu" ))
12371261 continue ;
@@ -1677,14 +1701,14 @@ static void __init prom_init_mem(void)
16771701
16781702 for (node = 0 ; prom_next_node (& node ); ) {
16791703 type [0 ] = 0 ;
1680- prom_getprop (node , "device_type" , type , sizeof (type ));
1704+ prom_getprop_string (node , "device_type" , type , sizeof (type ));
16811705
16821706 if (type [0 ] == 0 ) {
16831707 /*
16841708 * CHRP Longtrail machines have no device_type
16851709 * on the memory node, so check the name instead...
16861710 */
1687- prom_getprop (node , "name" , type , sizeof (type ));
1711+ prom_getprop_string (node , "name" , type , sizeof (type ));
16881712 }
16891713 if (prom_strcmp (type , "memory" ))
16901714 continue ;
@@ -2005,10 +2029,10 @@ static void __init prom_initialize_tce_table(void)
20052029 compatible [0 ] = 0 ;
20062030 type [0 ] = 0 ;
20072031 model [0 ] = 0 ;
2008- prom_getprop (node , "compatible" ,
2009- compatible , sizeof (compatible ));
2010- prom_getprop (node , "device_type" , type , sizeof (type ));
2011- prom_getprop (node , "model" , model , sizeof (model ));
2032+ prom_getprop_string (node , "compatible" , compatible ,
2033+ sizeof (compatible ));
2034+ prom_getprop_string (node , "device_type" , type , sizeof (type ));
2035+ prom_getprop_string (node , "model" , model , sizeof (model ));
20122036
20132037 if ((type [0 ] == 0 ) || (prom_strstr (type , "pci" ) == NULL ))
20142038 continue ;
@@ -2170,12 +2194,12 @@ static void __init prom_hold_cpus(void)
21702194 __be32 reg ;
21712195
21722196 type [0 ] = 0 ;
2173- prom_getprop (node , "device_type" , type , sizeof (type ));
2197+ prom_getprop_string (node , "device_type" , type , sizeof (type ));
21742198 if (prom_strcmp (type , "cpu" ) != 0 )
21752199 continue ;
21762200
21772201 /* Skip non-configured cpus. */
2178- if (prom_getprop (node , "status" , type , sizeof (type )) > 0 )
2202+ if (prom_getprop_string (node , "status" , type , sizeof (type )) > 0 )
21792203 if (prom_strcmp (type , "okay" ) != 0 )
21802204 continue ;
21812205
@@ -2248,9 +2272,8 @@ static void __init prom_find_mmu(void)
22482272 oprom = call_prom ("finddevice" , 1 , 1 , ADDR ("/openprom" ));
22492273 if (!PHANDLE_VALID (oprom ))
22502274 return ;
2251- if (prom_getprop (oprom , "model" , version , sizeof (version )) <= 0 )
2275+ if (prom_getprop_string (oprom , "model" , version , sizeof (version )) <= 0 )
22522276 return ;
2253- version [sizeof (version ) - 1 ] = 0 ;
22542277 /* XXX might need to add other versions here */
22552278 if (prom_strcmp (version , "Open Firmware, 1.0.5" ) == 0 )
22562279 of_workarounds = OF_WA_CLAIM ;
@@ -2296,7 +2319,8 @@ static void __init prom_init_stdout(void)
22962319
22972320 /* If it's a display, note it */
22982321 memset (type , 0 , sizeof (type ));
2299- prom_getprop (stdout_node , "device_type" , type , sizeof (type ));
2322+ prom_getprop_string (stdout_node , "device_type" , type ,
2323+ sizeof (type ));
23002324 if (prom_strcmp (type , "display" ) == 0 )
23012325 prom_setprop (stdout_node , path , "linux,boot-display" , NULL , 0 );
23022326 }
@@ -2343,8 +2367,8 @@ static int __init prom_find_machine_type(void)
23432367 * non-IBM designs !
23442368 * - it has /rtas
23452369 */
2346- len = prom_getprop (prom .root , "device_type" ,
2347- compat , sizeof (compat )- 1 );
2370+ len = prom_getprop_string (prom .root , "device_type" ,
2371+ compat , sizeof (compat ));
23482372 if (len <= 0 )
23492373 return PLATFORM_GENERIC ;
23502374 if (prom_strcmp (compat , "chrp" ))
@@ -2408,7 +2432,7 @@ static void __init prom_check_displays(void)
24082432 prom_debug ("Looking for displays\n" );
24092433 for (node = 0 ; prom_next_node (& node ); ) {
24102434 memset (type , 0 , sizeof (type ));
2411- prom_getprop (node , "device_type" , type , sizeof (type ));
2435+ prom_getprop_string (node , "device_type" , type , sizeof (type ));
24122436 if (prom_strcmp (type , "display" ) != 0 )
24132437 continue ;
24142438
@@ -2892,7 +2916,7 @@ static void __init fixup_device_tree_pmac(void)
28922916 // Some pmacs are missing #size-cells on escc or i2s nodes
28932917 for (node = 0 ; prom_next_node (& node ); ) {
28942918 type [0 ] = '\0' ;
2895- prom_getprop (node , "device_type" , type , sizeof (type ));
2919+ prom_getprop_string (node , "device_type" , type , sizeof (type ));
28962920 if (prom_strcmp (type , "escc" ) && prom_strcmp (type , "i2s" ) &&
28972921 prom_strcmp (type , "media-bay" ))
28982922 continue ;
@@ -2988,7 +3012,7 @@ static void __init fixup_device_tree_efika(void)
29883012 if (!PHANDLE_VALID (node ))
29893013 return ;
29903014
2991- rv = prom_getprop (node , "model" , prop , sizeof (prop ));
3015+ rv = prom_getprop_string (node , "model" , prop , sizeof (prop ));
29923016 if (rv == PROM_ERROR )
29933017 return ;
29943018 if (prom_strcmp (prop , "EFIKA5K2" ))
@@ -2998,13 +3022,14 @@ static void __init fixup_device_tree_efika(void)
29983022
29993023 /* Claiming to be 'chrp' is death */
30003024 node = call_prom ("finddevice" , 1 , 1 , ADDR ("/" ));
3001- rv = prom_getprop (node , "device_type" , prop , sizeof (prop ));
3025+ rv = prom_getprop_string (node , "device_type" , prop , sizeof (prop ));
30023026 if (rv != PROM_ERROR && (prom_strcmp (prop , "chrp" ) == 0 ))
30033027 prom_setprop (node , "/" , "device_type" , "efika" , sizeof ("efika" ));
30043028
30053029 /* CODEGEN,description is exposed in /proc/cpuinfo so
30063030 fix that too */
3007- rv = prom_getprop (node , "CODEGEN,description" , prop , sizeof (prop ));
3031+ rv = prom_getprop_string (node , "CODEGEN,description" , prop ,
3032+ sizeof (prop ));
30083033 if (rv != PROM_ERROR && (prom_strstr (prop , "CHRP" )))
30093034 prom_setprop (node , "/" , "CODEGEN,description" ,
30103035 "Efika 5200B PowerPC System" ,
0 commit comments