Date: Wed, 11 May 2016 18:20:02 +0000 (UTC) From: Oleksandr Tymoshenko <gonzo@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r299477 - in head/sys: arm/broadcom/bcm2835 arm/ti arm/ti/cpsw dev/fdt dev/gpio dev/ofw Message-ID: <201605111820.u4BIK2Lh061491@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: gonzo Date: Wed May 11 18:20:02 2016 New Revision: 299477 URL: https://svnweb.freebsd.org/changeset/base/299477 Log: 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 Modified: head/sys/arm/broadcom/bcm2835/bcm2835_gpio.c head/sys/arm/ti/cpsw/if_cpsw.c head/sys/arm/ti/ti_adc.c head/sys/arm/ti/ti_hwmods.c head/sys/arm/ti/ti_pinmux.c head/sys/dev/fdt/fdt_clock.c head/sys/dev/fdt/fdt_common.c head/sys/dev/fdt/fdt_pinctrl.c head/sys/dev/gpio/gpiokeys.c head/sys/dev/gpio/gpioled.c head/sys/dev/gpio/ofw_gpiobus.c head/sys/dev/ofw/openfirm.c head/sys/dev/ofw/openfirm.h Modified: head/sys/arm/broadcom/bcm2835/bcm2835_gpio.c ============================================================================== --- head/sys/arm/broadcom/bcm2835/bcm2835_gpio.c Wed May 11 18:03:51 2016 (r299476) +++ head/sys/arm/broadcom/bcm2835/bcm2835_gpio.c Wed May 11 18:20:02 2016 (r299477) @@ -632,7 +632,7 @@ bcm_gpio_get_ro_pins(struct bcm_gpio_sof 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_sof 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_gp return (-1); if (strcmp(name, "reserved") == 0) reserved = node; - free(name, M_OFWPROP); + OF_prop_free(name); node = OF_peer(node); } if (reserved == 0) Modified: head/sys/arm/ti/cpsw/if_cpsw.c ============================================================================== --- head/sys/arm/ti/cpsw/if_cpsw.c Wed May 11 18:03:51 2016 (r299476) +++ head/sys/arm/ti/cpsw/if_cpsw.c Wed May 11 18:20:02 2016 (r299477) @@ -727,10 +727,10 @@ cpsw_get_fdt_data(struct cpsw_softc *sc, 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; Modified: head/sys/arm/ti/ti_adc.c ============================================================================== --- head/sys/arm/ti/ti_adc.c Wed May 11 18:03:51 2016 (r299476) +++ head/sys/arm/ti/ti_adc.c Wed May 11 18:20:02 2016 (r299477) @@ -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); } } Modified: head/sys/arm/ti/ti_hwmods.c ============================================================================== --- head/sys/arm/ti/ti_hwmods.c Wed May 11 18:03:51 2016 (r299476) +++ head/sys/arm/ti/ti_hwmods.c Wed May 11 18:20:02 2016 (r299477) @@ -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, con len -= l; } - free(buf, M_OFWPROP); + OF_prop_free(buf); return (result); } @@ -200,6 +200,6 @@ ti_hwmods_get_unit(device_t dev, const c len -= l; } - free(buf, M_OFWPROP); + OF_prop_free(buf); return (result); } Modified: head/sys/arm/ti/ti_pinmux.c ============================================================================== --- head/sys/arm/ti/ti_pinmux.c Wed May 11 18:03:51 2016 (r299476) +++ head/sys/arm/ti/ti_pinmux.c Wed May 11 18:20:02 2016 (r299477) @@ -361,7 +361,7 @@ ti_pinmux_configure_pins(device_t dev, p ti_pinmux_write_2(sc, cfg->reg, cfg->conf); } - free(cfgtuples, M_OFWPROP); + OF_prop_free(cfgtuples); return (0); } Modified: head/sys/dev/fdt/fdt_clock.c ============================================================================== --- head/sys/dev/fdt/fdt_clock.c Wed May 11 18:03:51 2016 (r299476) +++ head/sys/dev/fdt/fdt_clock.c Wed May 11 18:20:02 2016 (r299477) @@ -89,7 +89,7 @@ enable_disable_all(device_t consumer, bo 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, in err = FDT_CLOCK_GET_INFO(clockdev, clocknum, info); } } - free(clks, M_OFWPROP); + OF_prop_free(clks); return (err); } Modified: head/sys/dev/fdt/fdt_common.c ============================================================================== --- head/sys/dev/fdt/fdt_common.c Wed May 11 18:03:51 2016 (r299476) +++ head/sys/dev/fdt/fdt_common.c Wed May 11 18:20:02 2016 (r299477) @@ -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 res rv = 0; out: - free(regptr, M_OFWPROP); + OF_prop_free(regptr); return (rv); } @@ -734,4 +734,4 @@ fdt_get_chosen_bootargs(char *bootargs, if (OF_getprop(chosen, "bootargs", bootargs, max_size) == -1) return (ENXIO); return (0); -} \ No newline at end of file +} Modified: head/sys/dev/fdt/fdt_pinctrl.c ============================================================================== --- head/sys/dev/fdt/fdt_pinctrl.c Wed May 11 18:03:51 2016 (r299476) +++ head/sys/dev/fdt/fdt_pinctrl.c Wed May 11 18:20:02 2016 (r299477) @@ -56,7 +56,7 @@ fdt_pinctrl_configure(device_t client, u 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 c 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 pinc if (OF_device_from_xref(configs[i]) == pinctrl) FDT_PINCTRL_CONFIGURE(pinctrl, configs[i]); } - free(configs, M_OFWPROP); + OF_prop_free(configs); } return (0); } Modified: head/sys/dev/gpio/gpiokeys.c ============================================================================== --- head/sys/dev/gpio/gpiokeys.c Wed May 11 18:03:51 2016 (r299476) +++ head/sys/dev/gpio/gpiokeys.c Wed May 11 18:20:02 2016 (r299477) @@ -309,7 +309,7 @@ gpiokeys_attach_key(struct gpiokeys_soft 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_soft 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_soft 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_soft key->autorepeat, key->repeat, key->repeat_delay); if (name) - free(name, M_OFWPROP); + OF_prop_free(name); } static void Modified: head/sys/dev/gpio/gpioled.c ============================================================================== --- head/sys/dev/gpio/gpioled.c Wed May 11 18:03:51 2016 (r299476) +++ head/sys/dev/gpio/gpioled.c Wed May 11 18:20:02 2016 (r299477) @@ -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); Modified: head/sys/dev/gpio/ofw_gpiobus.c ============================================================================== --- head/sys/dev/gpio/ofw_gpiobus.c Wed May 11 18:03:51 2016 (r299476) +++ head/sys/dev/gpio/ofw_gpiobus.c Wed May 11 18:20:02 2016 (r299477) @@ -76,21 +76,21 @@ gpio_pin_get_by_ofw_impl(device_t consum /* 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 co 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 co 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 co 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); } Modified: head/sys/dev/ofw/openfirm.c ============================================================================== --- head/sys/dev/ofw/openfirm.c Wed May 11 18:03:51 2016 (r299476) +++ head/sys/dev/ofw/openfirm.c Wed May 11 18:20:02 2016 (r299477) @@ -477,6 +477,13 @@ OF_getencprop_alloc(phandle_t package, c 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) Modified: head/sys/dev/ofw/openfirm.h ============================================================================== --- head/sys/dev/ofw/openfirm.h Wed May 11 18:03:51 2016 (r299476) +++ head/sys/dev/ofw/openfirm.h Wed May 11 18:20:02 2016 (r299477) @@ -117,6 +117,7 @@ ssize_t OF_getprop_alloc(phandle_t node 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,
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605111820.u4BIK2Lh061491>