Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F149630167
D43370.id132508.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D43370.id132508.diff
View Options
diff --git a/share/man/man9/device_set_desc.9 b/share/man/man9/device_set_desc.9
--- a/share/man/man9/device_set_desc.9
+++ b/share/man/man9/device_set_desc.9
@@ -26,11 +26,12 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd June 16, 1998
+.Dd January 9, 2024
.Dt DEVICE_SET_DESC 9
.Os
.Sh NAME
.Nm device_set_desc ,
+.Nm device_set_descf ,
.Nm device_set_desc_copy ,
.Nm device_get_desc
.Nd access the description of a device
@@ -40,6 +41,8 @@
.Ft void
.Fn device_set_desc "device_t dev" "const char *desc"
.Ft void
+.Fn device_set_descf "device_t dev" "const char *fmt" "..."
+.Ft void
.Fn device_set_desc_copy "device_t dev" "const char *desc"
.Ft const char *
.Fn device_get_desc "device_t dev"
@@ -54,6 +57,9 @@
buffer which will be overwritten.
In this case, the system will copy
the string, otherwise the pointer passed will be used directly.
+.Fn device_set_descf
+is a printf-like version of
+.Fn device_set_desc .
.Sh SEE ALSO
.Xr device 9
.Sh AUTHORS
diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c
--- a/sys/kern/subr_bus.c
+++ b/sys/kern/subr_bus.c
@@ -1997,7 +1997,7 @@
* @internal
*/
static void
-device_set_desc_internal(device_t dev, const char* desc, int copy)
+device_set_desc_internal(device_t dev, const char *desc, bool alloced)
{
if (dev->desc && (dev->flags & DF_DESCMALLOCED)) {
free(dev->desc, M_BUS);
@@ -2005,16 +2005,9 @@
dev->desc = NULL;
}
- if (copy && desc) {
- dev->desc = malloc(strlen(desc) + 1, M_BUS, M_NOWAIT);
- if (dev->desc) {
- strcpy(dev->desc, desc);
- dev->flags |= DF_DESCMALLOCED;
- }
- } else {
- /* Avoid a -Wcast-qual warning */
- dev->desc = (char *)(uintptr_t) desc;
- }
+ if (alloced && desc)
+ dev->flags |= DF_DESCMALLOCED;
+ dev->desc = __DECONST(char *, desc);
bus_data_generation_update();
}
@@ -2027,9 +2020,26 @@
* call to device_set_desc() or device_set_desc_copy()).
*/
void
-device_set_desc(device_t dev, const char* desc)
+device_set_desc(device_t dev, const char *desc)
+{
+ device_set_desc_internal(dev, desc, false);
+}
+
+/**
+ * @brief Set the device's description
+ *
+ * A printf-like version of device_set_desc().
+ */
+void
+device_set_descf(device_t dev, const char *fmt, ...)
{
- device_set_desc_internal(dev, desc, FALSE);
+ va_list ap;
+ char *buf = NULL;
+
+ va_start(ap, fmt);
+ vasprintf(&buf, M_BUS, fmt, ap);
+ va_end(ap);
+ device_set_desc_internal(dev, buf, true);
}
/**
@@ -2039,9 +2049,12 @@
* the device description is generated, (e.g. with sprintf()).
*/
void
-device_set_desc_copy(device_t dev, const char* desc)
+device_set_desc_copy(device_t dev, const char *desc)
{
- device_set_desc_internal(dev, desc, TRUE);
+ char *buf;
+
+ buf = strdup_flags(desc, M_BUS, M_NOWAIT);
+ device_set_desc_internal(dev, buf, true);
}
/**
diff --git a/sys/sys/bus.h b/sys/sys/bus.h
--- a/sys/sys/bus.h
+++ b/sys/sys/bus.h
@@ -660,6 +660,7 @@
void device_quiet(device_t dev);
void device_quiet_children(device_t dev);
void device_set_desc(device_t dev, const char* desc);
+void device_set_descf(device_t dev, const char* fmt, ...) __printflike(2, 3);
void device_set_desc_copy(device_t dev, const char* desc);
int device_set_devclass(device_t dev, const char *classname);
int device_set_devclass_fixed(device_t dev, const char *classname);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Mar 26, 7:53 PM (13 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
30360206
Default Alt Text
D43370.id132508.diff (3 KB)
Attached To
Mode
D43370: subr_bus: introduce device_set_descf() and modify allocation logic
Attached
Detach File
Event Timeline
Log In to Comment