Skip to contentSkip to conversation

OHW OF_setprop() zero-sized property

PATCH New Thayne Harbaugh 1 participant 1 message Feb 24, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 OHW OF_setprop() zero-sized property

The current implementation of OF_setprop() doesn't allow for value-less or zero-sized properties to be set. This breaks Linux 2.6 frame buffer since arch/ppc/syslib/prom_init.c:check_display() marks displays with a value-less property "linux,opened" and then drivers/video/offb.c:offb_init() later finds these displays marked with "linux,opened".

of.c +6 -3
Index: src/of.c
===================================================================
@@ -3769,7 +3776,7 @@
 static void OF_setprop (OF_env_t *OF_env)
 {
     unsigned char name[OF_NAMELEN_MAX], *namep;
-    unsigned char *value, *buffer;
+    unsigned char *value = NULL, *buffer;
     OF_node_t *node;
     OF_prop_t *prop;
     uint32_t phandle;
@@ -3780,12 +3787,15 @@
         ERROR("Cannot get pack %04x\n", phandle);
         return;
     }
-    value = malloc(len);
-    if (value == NULL) {
+    if (len && !(value = malloc(len))) {
         pushd(OF_env, -1);
         ERROR("%s: Cannot alloc property\n", __func__);
         return;
     }
+    if (!len && value) {
+	pushd(OF_env, -1);
+	ERROR("%s: NULL buffer for non-zero sized property!\n", __func__);
+    }
     for (i = 0; i < len; i++)
         value[i] = buffer[i];
     prop = OF_property_set(OF_env, node, name, value, len);