Add OF_prop_free function as a counterpart for OF_*prop_alloc
- Introduce new OF API function OF_prop_free to free memory allocated by OF_getprop_alloc and OF_getencprop_alloc. Current code just calls free(9) with M_OFWPROP memory class which assumes knowledge about OF_*prop_alloc functions' internals and leads to unneccessary code coupling - Convert some of the free(..., M_OFWPROP) instances to OF_prop_free Files affected by this commit are the ones I was able to test on real hardware. The rest of free(..., M_OFWPROP) instances will be handled with idividual maintainers Reviewed by: andrew Differential Revision: https://reviews.freebsd.org/D6315
This commit is contained in:
parent
8093b741c7
commit
23a2d5f593
@ -632,7 +632,7 @@ bcm_gpio_get_ro_pins(struct bcm_gpio_softc *sc, phandle_t node,
|
||||
if (npins < 0)
|
||||
return (-1);
|
||||
if (npins == 0) {
|
||||
free(pins, M_OFWPROP);
|
||||
OF_prop_free(pins);
|
||||
return (0);
|
||||
}
|
||||
for (i = 0; i < npins; i++)
|
||||
@ -660,7 +660,7 @@ bcm_gpio_get_ro_pins(struct bcm_gpio_softc *sc, phandle_t node,
|
||||
printf("%d-%d.\n", range_start, range_stop);
|
||||
else
|
||||
printf("%d.\n", range_start);
|
||||
free(pins, M_OFWPROP);
|
||||
OF_prop_free(pins);
|
||||
|
||||
return (0);
|
||||
}
|
||||
@ -686,7 +686,7 @@ bcm_gpio_get_reserved_pins(struct bcm_gpio_softc *sc)
|
||||
return (-1);
|
||||
if (strcmp(name, "reserved") == 0)
|
||||
reserved = node;
|
||||
free(name, M_OFWPROP);
|
||||
OF_prop_free(name);
|
||||
node = OF_peer(node);
|
||||
}
|
||||
if (reserved == 0)
|
||||
|
@ -727,10 +727,10 @@ cpsw_get_fdt_data(struct cpsw_softc *sc, int port)
|
||||
if (OF_getprop_alloc(child, "name", 1, (void **)&name) < 0)
|
||||
continue;
|
||||
if (sscanf(name, "slave@%x", &mdio_child_addr) != 1) {
|
||||
free(name, M_OFWPROP);
|
||||
OF_prop_free(name);
|
||||
continue;
|
||||
}
|
||||
free(name, M_OFWPROP);
|
||||
OF_prop_free(name);
|
||||
if (mdio_child_addr != slave_mdio_addr[port])
|
||||
continue;
|
||||
|
||||
|
@ -747,11 +747,11 @@ ti_adc_attach(device_t dev)
|
||||
device_printf(sc->sc_dev,
|
||||
"invalid nubmer of ti,wire-config: %d (should be %d)\n",
|
||||
nwire_configs, sc->sc_tsc_wires);
|
||||
free(wire_configs, M_OFWPROP);
|
||||
OF_prop_free(wire_configs);
|
||||
return (EINVAL);
|
||||
}
|
||||
err = ti_adc_config_wires(sc, wire_configs, nwire_configs);
|
||||
free(wire_configs, M_OFWPROP);
|
||||
OF_prop_free(wire_configs);
|
||||
if (err)
|
||||
return (EINVAL);
|
||||
}
|
||||
@ -764,7 +764,7 @@ ti_adc_attach(device_t dev)
|
||||
if (sc->sc_adc_nchannels > 0) {
|
||||
for (i = 0; i < sc->sc_adc_nchannels; i++)
|
||||
sc->sc_adc_channels[i] = channels[i];
|
||||
free(channels, M_OFWPROP);
|
||||
OF_prop_free(channels);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ ti_hwmods_get_clock(device_t dev)
|
||||
if (len > 0)
|
||||
device_printf(dev, "WARNING: more than one ti,hwmod \n");
|
||||
|
||||
free(buf, M_OFWPROP);
|
||||
OF_prop_free(buf);
|
||||
return (clk);
|
||||
}
|
||||
|
||||
@ -167,7 +167,7 @@ int ti_hwmods_contains(device_t dev, const char *hwmod)
|
||||
len -= l;
|
||||
}
|
||||
|
||||
free(buf, M_OFWPROP);
|
||||
OF_prop_free(buf);
|
||||
|
||||
return (result);
|
||||
}
|
||||
@ -200,6 +200,6 @@ ti_hwmods_get_unit(device_t dev, const char *hwmod)
|
||||
len -= l;
|
||||
}
|
||||
|
||||
free(buf, M_OFWPROP);
|
||||
OF_prop_free(buf);
|
||||
return (result);
|
||||
}
|
||||
|
@ -361,7 +361,7 @@ ti_pinmux_configure_pins(device_t dev, phandle_t cfgxref)
|
||||
ti_pinmux_write_2(sc, cfg->reg, cfg->conf);
|
||||
}
|
||||
|
||||
free(cfgtuples, M_OFWPROP);
|
||||
OF_prop_free(cfgtuples);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ enable_disable_all(device_t consumer, boolean_t enable)
|
||||
anyerrors = true;
|
||||
}
|
||||
}
|
||||
free(clks, M_OFWPROP);
|
||||
OF_prop_free(clks);
|
||||
return (anyerrors ? ENXIO : 0);
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ fdt_clock_get_info(device_t consumer, int n, struct fdt_clock_info *info)
|
||||
err = FDT_CLOCK_GET_INFO(clockdev, clocknum, info);
|
||||
}
|
||||
}
|
||||
free(clks, M_OFWPROP);
|
||||
OF_prop_free(clks);
|
||||
return (err);
|
||||
}
|
||||
|
||||
|
@ -348,7 +348,7 @@ fdt_is_enabled(phandle_t node)
|
||||
if (strncmp((char *)stat, "okay", len) == 0)
|
||||
ena = 1;
|
||||
|
||||
free(stat, M_OFWPROP);
|
||||
OF_prop_free(stat);
|
||||
return (ena);
|
||||
}
|
||||
|
||||
@ -519,7 +519,7 @@ fdt_reg_to_rl(phandle_t node, struct resource_list *rl)
|
||||
rv = 0;
|
||||
|
||||
out:
|
||||
free(regptr, M_OFWPROP);
|
||||
OF_prop_free(regptr);
|
||||
return (rv);
|
||||
}
|
||||
|
||||
@ -734,4 +734,4 @@ fdt_get_chosen_bootargs(char *bootargs, size_t max_size)
|
||||
if (OF_getprop(chosen, "bootargs", bootargs, max_size) == -1)
|
||||
return (ENXIO);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ fdt_pinctrl_configure(device_t client, u_int index)
|
||||
if ((pinctrl = OF_device_from_xref(configs[i])) != NULL)
|
||||
FDT_PINCTRL_CONFIGURE(pinctrl, configs[i]);
|
||||
}
|
||||
free(configs, M_OFWPROP);
|
||||
OF_prop_free(configs);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ fdt_pinctrl_configure_by_name(device_t client, const char * name)
|
||||
break;
|
||||
offset += strlen(&names[offset]) + 1;
|
||||
}
|
||||
free(names, M_OFWPROP);
|
||||
OF_prop_free(names);
|
||||
if (offset < nameslen)
|
||||
return (fdt_pinctrl_configure(client, i));
|
||||
else
|
||||
@ -136,7 +136,7 @@ pinctrl_configure_children(device_t pinctrl, phandle_t parent)
|
||||
if (OF_device_from_xref(configs[i]) == pinctrl)
|
||||
FDT_PINCTRL_CONFIGURE(pinctrl, configs[i]);
|
||||
}
|
||||
free(configs, M_OFWPROP);
|
||||
OF_prop_free(configs);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
@ -309,7 +309,7 @@ gpiokeys_attach_key(struct gpiokeys_softc *sc, phandle_t node,
|
||||
if (err) {
|
||||
device_printf(sc->sc_dev, "<%s> failed to map pin\n", key_name);
|
||||
if (name)
|
||||
free(name, M_OFWPROP);
|
||||
OF_prop_free(name);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -320,7 +320,7 @@ gpiokeys_attach_key(struct gpiokeys_softc *sc, phandle_t node,
|
||||
gpio_pin_release(key->pin);
|
||||
key->pin = NULL;
|
||||
if (name)
|
||||
free(name, M_OFWPROP);
|
||||
OF_prop_free(name);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -334,7 +334,7 @@ gpiokeys_attach_key(struct gpiokeys_softc *sc, phandle_t node,
|
||||
key->pin = NULL;
|
||||
key->irq_res = NULL;
|
||||
if (name)
|
||||
free(name, M_OFWPROP);
|
||||
OF_prop_free(name);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -344,7 +344,7 @@ gpiokeys_attach_key(struct gpiokeys_softc *sc, phandle_t node,
|
||||
key->autorepeat, key->repeat, key->repeat_delay);
|
||||
|
||||
if (name)
|
||||
free(name, M_OFWPROP);
|
||||
OF_prop_free(name);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -151,7 +151,7 @@ gpioled_probe(device_t dev)
|
||||
if (strcasecmp(compat, "gpio-leds") == 0)
|
||||
match = 1;
|
||||
|
||||
free(compat, M_OFWPROP);
|
||||
OF_prop_free(compat);
|
||||
}
|
||||
|
||||
if (match == 0)
|
||||
@ -198,7 +198,7 @@ gpioled_attach(device_t dev)
|
||||
device_printf(dev,
|
||||
"unknown value for default-state in FDT\n");
|
||||
}
|
||||
free(default_state, M_OFWPROP);
|
||||
OF_prop_free(default_state);
|
||||
}
|
||||
|
||||
name = NULL;
|
||||
@ -214,7 +214,7 @@ gpioled_attach(device_t dev)
|
||||
device_get_nameunit(dev), state);
|
||||
#ifdef FDT
|
||||
if (name != NULL)
|
||||
free(name, M_OFWPROP);
|
||||
OF_prop_free(name);
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
|
@ -76,21 +76,21 @@ gpio_pin_get_by_ofw_impl(device_t consumer, phandle_t cnode,
|
||||
/* Translate provider to device. */
|
||||
pin.dev = OF_device_from_xref(xref);
|
||||
if (pin.dev == NULL) {
|
||||
free(cells, M_OFWPROP);
|
||||
OF_prop_free(cells);
|
||||
return (ENODEV);
|
||||
}
|
||||
|
||||
/* Test if GPIO bus already exist. */
|
||||
busdev = GPIO_GET_BUS(pin.dev);
|
||||
if (busdev == NULL) {
|
||||
free(cells, M_OFWPROP);
|
||||
OF_prop_free(cells);
|
||||
return (ENODEV);
|
||||
}
|
||||
|
||||
/* Map GPIO pin. */
|
||||
rv = gpio_map_gpios(pin.dev, cnode, OF_node_from_xref(xref), ncells,
|
||||
cells, &pin.pin, &pin.flags);
|
||||
free(cells, M_OFWPROP);
|
||||
OF_prop_free(cells);
|
||||
if (rv != 0)
|
||||
return (ENXIO);
|
||||
|
||||
@ -379,7 +379,7 @@ ofw_gpiobus_parse_gpios_impl(device_t consumer, phandle_t cnode, char *pname,
|
||||
sizeof(gpiocells)) < 0) {
|
||||
device_printf(consumer,
|
||||
"gpio reference is not a gpio-controller.\n");
|
||||
free(gpios, M_OFWPROP);
|
||||
OF_prop_free(gpios);
|
||||
return (-1);
|
||||
}
|
||||
if (ncells - i < gpiocells + 1) {
|
||||
@ -394,13 +394,13 @@ ofw_gpiobus_parse_gpios_impl(device_t consumer, phandle_t cnode, char *pname,
|
||||
if (npins == 0)
|
||||
device_printf(consumer, "no pin specified in %s.\n",
|
||||
pname);
|
||||
free(gpios, M_OFWPROP);
|
||||
OF_prop_free(gpios);
|
||||
return (npins);
|
||||
}
|
||||
*pins = malloc(sizeof(struct gpiobus_pin) * npins, M_DEVBUF,
|
||||
M_NOWAIT | M_ZERO);
|
||||
if (*pins == NULL) {
|
||||
free(gpios, M_OFWPROP);
|
||||
OF_prop_free(gpios);
|
||||
return (-1);
|
||||
}
|
||||
/* Decode the gpio specifier on the second pass. */
|
||||
@ -455,12 +455,12 @@ ofw_gpiobus_parse_gpios_impl(device_t consumer, phandle_t cnode, char *pname,
|
||||
j++;
|
||||
i += gpiocells + 1;
|
||||
}
|
||||
free(gpios, M_OFWPROP);
|
||||
OF_prop_free(gpios);
|
||||
|
||||
return (npins);
|
||||
|
||||
fail:
|
||||
free(gpios, M_OFWPROP);
|
||||
OF_prop_free(gpios);
|
||||
free(*pins, M_DEVBUF);
|
||||
return (-1);
|
||||
}
|
||||
|
@ -477,6 +477,13 @@ OF_getencprop_alloc(phandle_t package, const char *name, int elsz, void **buf)
|
||||
return (retval);
|
||||
}
|
||||
|
||||
/* Free buffer allocated by OF_getencprop_alloc or OF_getprop_alloc */
|
||||
void OF_prop_free(void *buf)
|
||||
{
|
||||
|
||||
free(buf, M_OFWPROP);
|
||||
}
|
||||
|
||||
/* Get the next property of a package. */
|
||||
int
|
||||
OF_nextprop(phandle_t package, const char *previous, char *buf, size_t size)
|
||||
|
@ -117,6 +117,7 @@ ssize_t OF_getprop_alloc(phandle_t node, const char *propname,
|
||||
int elsz, void **buf);
|
||||
ssize_t OF_getencprop_alloc(phandle_t node, const char *propname,
|
||||
int elsz, void **buf);
|
||||
void OF_prop_free(void *buf);
|
||||
int OF_nextprop(phandle_t node, const char *propname, char *buf,
|
||||
size_t len);
|
||||
int OF_setprop(phandle_t node, const char *name, const void *buf,
|
||||
|
Loading…
x
Reference in New Issue
Block a user