subr_bus.c (ed88eef140a1c3d57d546f409c216806dd3da809) subr_bus.c (6b6914c1e21b625503a1b8d8d5cfdfbc4c6a6acd)
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 1997,1998,2003 Doug Rabson
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 1983 unchanged lines hidden (view full) ---

1992
1993 return (retval);
1994}
1995
1996/**
1997 * @internal
1998 */
1999static void
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 1997,1998,2003 Doug Rabson
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 1983 unchanged lines hidden (view full) ---

1992
1993 return (retval);
1994}
1995
1996/**
1997 * @internal
1998 */
1999static void
2000device_set_desc_internal(device_t dev, const char* desc, int copy)
2000device_set_desc_internal(device_t dev, const char *desc, bool allocated)
2001{
2002 if (dev->desc && (dev->flags & DF_DESCMALLOCED)) {
2003 free(dev->desc, M_BUS);
2004 dev->flags &= ~DF_DESCMALLOCED;
2005 dev->desc = NULL;
2006 }
2007
2001{
2002 if (dev->desc && (dev->flags & DF_DESCMALLOCED)) {
2003 free(dev->desc, M_BUS);
2004 dev->flags &= ~DF_DESCMALLOCED;
2005 dev->desc = NULL;
2006 }
2007
2008 if (copy && desc) {
2009 dev->desc = malloc(strlen(desc) + 1, M_BUS, M_NOWAIT);
2010 if (dev->desc) {
2011 strcpy(dev->desc, desc);
2012 dev->flags |= DF_DESCMALLOCED;
2013 }
2014 } else {
2015 /* Avoid a -Wcast-qual warning */
2016 dev->desc = (char *)(uintptr_t) desc;
2017 }
2008 if (allocated && desc)
2009 dev->flags |= DF_DESCMALLOCED;
2010 dev->desc = __DECONST(char *, desc);
2018
2019 bus_data_generation_update();
2020}
2021
2022/**
2023 * @brief Set the device's description
2024 *
2025 * The value of @c desc should be a string constant that will not
2026 * change (at least until the description is changed in a subsequent
2027 * call to device_set_desc() or device_set_desc_copy()).
2028 */
2029void
2011
2012 bus_data_generation_update();
2013}
2014
2015/**
2016 * @brief Set the device's description
2017 *
2018 * The value of @c desc should be a string constant that will not
2019 * change (at least until the description is changed in a subsequent
2020 * call to device_set_desc() or device_set_desc_copy()).
2021 */
2022void
2030device_set_desc(device_t dev, const char* desc)
2023device_set_desc(device_t dev, const char *desc)
2031{
2024{
2032 device_set_desc_internal(dev, desc, FALSE);
2025 device_set_desc_internal(dev, desc, false);
2033}
2034
2035/**
2036 * @brief Set the device's description
2037 *
2026}
2027
2028/**
2029 * @brief Set the device's description
2030 *
2031 * A printf-like version of device_set_desc().
2032 */
2033void
2034device_set_descf(device_t dev, const char *fmt, ...)
2035{
2036 va_list ap;
2037 char *buf = NULL;
2038
2039 va_start(ap, fmt);
2040 vasprintf(&buf, M_BUS, fmt, ap);
2041 va_end(ap);
2042 device_set_desc_internal(dev, buf, true);
2043}
2044
2045/**
2046 * @brief Set the device's description
2047 *
2038 * The string pointed to by @c desc is copied. Use this function if
2039 * the device description is generated, (e.g. with sprintf()).
2040 */
2041void
2048 * The string pointed to by @c desc is copied. Use this function if
2049 * the device description is generated, (e.g. with sprintf()).
2050 */
2051void
2042device_set_desc_copy(device_t dev, const char* desc)
2052device_set_desc_copy(device_t dev, const char *desc)
2043{
2053{
2044 device_set_desc_internal(dev, desc, TRUE);
2054 char *buf;
2055
2056 buf = strdup_flags(desc, M_BUS, M_NOWAIT);
2057 device_set_desc_internal(dev, buf, true);
2045}
2046
2047/**
2048 * @brief Set the device's flags
2049 */
2050void
2051device_set_flags(device_t dev, uint32_t flags)
2052{

--- 4001 unchanged lines hidden ---
2058}
2059
2060/**
2061 * @brief Set the device's flags
2062 */
2063void
2064device_set_flags(device_t dev, uint32_t flags)
2065{

--- 4001 unchanged lines hidden ---