udev: add some asserts
authorTom Gundersen <teg@jklm.no>
Tue, 2 Jun 2015 14:52:07 +0000 (16:52 +0200)
committerTom Gundersen <teg@jklm.no>
Tue, 2 Jun 2015 16:12:47 +0000 (18:12 +0200)
Mostly for documentation purposes.

src/udev/net/link-config.c
src/udev/udev-builtin-hwdb.c
src/udev/udev-builtin-input_id.c
src/udev/udev-builtin-keyboard.c
src/udev/udev-builtin-net_id.c
src/udev/udev-builtin-path_id.c
src/udev/udev-builtin-usb_id.c
src/udev/udev-event.c
src/udev/udev-rules.c
src/udev/udevd.c

index ce038ab..5610b28 100644 (file)
@@ -240,6 +240,10 @@ int link_config_get(link_config_ctx *ctx, struct udev_device *device,
                     link_config **ret) {
         link_config *link;
 
+        assert(ctx);
+        assert(device);
+        assert(ret);
+
         LIST_FOREACH(links, link, ctx->links) {
                 const char* attr_value;
 
index 5e0e7eb..7dfc74e 100644 (file)
@@ -85,6 +85,8 @@ static int udev_builtin_hwdb_search(struct udev_device *dev, struct udev_device
         bool last = false;
         int r = 0;
 
+        assert(dev);
+
         for (d = srcdev; d && !last; d = udev_device_get_parent(d)) {
                 const char *dsubsys;
                 const char *modalias = NULL;
index b14190e..6d06cef 100644 (file)
@@ -268,6 +268,8 @@ static int builtin_input_id(struct udev_device *dev, int argc, char *argv[], boo
         bool is_pointer;
         bool is_key;
 
+        assert(dev);
+
         /* walk up the parental chain until we find the real input device; the
          * argument is very likely a subdevice of this, like eventN */
         pdev = dev;
index ed990c5..01f3879 100644 (file)
@@ -37,6 +37,9 @@ static int install_force_release(struct udev_device *dev, const unsigned *releas
         unsigned i;
         int ret;
 
+        assert(dev);
+        assert(release);
+
         atkbd = udev_device_get_parent_with_subsystem_devtype(dev, "serio", NULL);
         if (!atkbd)
                 return -ENODEV;
@@ -152,6 +155,9 @@ static void set_trackpoint_sensitivity(struct udev_device *dev, const char *valu
         char val_s[DECIMAL_STR_MAX(int)];
         int r, val_i;
 
+        assert(dev);
+        assert(value);
+
         /* The sensitivity sysfs attr belongs to the serio parent device */
         pdev = udev_device_get_parent_with_subsystem_devtype(dev, "serio", NULL);
         if (!pdev) {
index 4489205..6e7e127 100644 (file)
@@ -276,6 +276,9 @@ out:
 static int names_pci(struct udev_device *dev, struct netnames *names) {
         struct udev_device *parent;
 
+        assert(dev);
+        assert(names);
+
         parent = udev_device_get_parent(dev);
         if (!parent)
                 return -ENOENT;
@@ -302,6 +305,9 @@ static int names_usb(struct udev_device *dev, struct netnames *names) {
         size_t l;
         char *s;
 
+        assert(dev);
+        assert(names);
+
         usbdev = udev_device_get_parent_with_subsystem_devtype(dev, "usb", "usb_interface");
         if (!usbdev)
                 return -ENOENT;
@@ -350,6 +356,9 @@ static int names_bcma(struct udev_device *dev, struct netnames *names) {
         struct udev_device *bcmadev;
         unsigned int core;
 
+        assert(dev);
+        assert(names);
+
         bcmadev = udev_device_get_parent_with_subsystem_devtype(dev, "bcma", NULL);
         if (!bcmadev)
                 return -ENOENT;
@@ -371,6 +380,9 @@ static int names_ccw(struct  udev_device *dev, struct netnames *names) {
         size_t bus_id_len;
         int rc;
 
+        assert(dev);
+        assert(names);
+
         /* Retrieve the associated CCW device */
         cdev = udev_device_get_parent(dev);
         if (!cdev)
index b6749aa..0fa11f6 100644 (file)
@@ -77,6 +77,9 @@ static int format_lun_number(struct udev_device *dev, char **path) {
 static struct udev_device *skip_subsystem(struct udev_device *dev, const char *subsys) {
         struct udev_device *parent = dev;
 
+        assert(dev);
+        assert(subsys);
+
         while (parent != NULL) {
                 const char *subsystem;
 
@@ -96,6 +99,9 @@ static struct udev_device *handle_scsi_fibre_channel(struct udev_device *parent,
         const char *port;
         char *lun = NULL;
 
+        assert(parent);
+        assert(path);
+
         targetdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_target");
         if (targetdev == NULL)
                 return NULL;
@@ -126,6 +132,9 @@ static struct udev_device *handle_scsi_sas_wide_port(struct udev_device *parent,
         const char *sas_address;
         char *lun = NULL;
 
+        assert(parent);
+        assert(path);
+
         targetdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_target");
         if (targetdev == NULL)
                 return NULL;
@@ -169,6 +178,9 @@ static struct udev_device *handle_scsi_sas(struct udev_device *parent, char **pa
         const char *phy_count;
         char *lun = NULL;
 
+        assert(parent);
+        assert(path);
+
         targetdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_target");
         if (targetdev == NULL)
                 return NULL;
@@ -259,6 +271,9 @@ static struct udev_device *handle_scsi_iscsi(struct udev_device *parent, char **
         const char *port;
         char *lun = NULL;
 
+        assert(parent);
+        assert(path);
+
         /* find iscsi session */
         transportdev = parent;
         for (;;) {
@@ -316,6 +331,9 @@ static struct udev_device *handle_scsi_default(struct udev_device *parent, char
         struct dirent *dent;
         int basenum;
 
+        assert(parent);
+        assert(path);
+
         hostdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_host");
         if (hostdev == NULL)
                 return NULL;
@@ -398,6 +416,9 @@ static struct udev_device *handle_scsi_hyperv(struct udev_device *parent, char *
         char guid[38];
         size_t i, k;
 
+        assert(parent);
+        assert(path);
+
         hostdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_host");
         if (!hostdev)
                 return NULL;
@@ -555,6 +576,10 @@ static struct udev_device *handle_bcma(struct udev_device *parent, char **path)
 static struct udev_device *handle_ccw(struct udev_device *parent, struct udev_device *dev, char **path) {
         struct udev_device *scsi_dev;
 
+        assert(parent);
+        assert(dev);
+        assert(path);
+
         scsi_dev = udev_device_get_parent_with_subsystem_devtype(dev, "scsi", "scsi_device");
         if (scsi_dev != NULL) {
                 const char *wwpn;
@@ -582,6 +607,8 @@ static int builtin_path_id(struct udev_device *dev, int argc, char *argv[], bool
         bool supported_transport = false;
         bool supported_parent = false;
 
+        assert(dev);
+
         /* S390 ccw bus */
         parent = udev_device_get_parent_with_subsystem_devtype(dev, "ccw", NULL);
         if (parent != NULL) {
index 462efc5..d309dc3 100644 (file)
@@ -252,6 +252,8 @@ static int builtin_usb_id(struct udev_device *dev, int argc, char *argv[], bool
         size_t l;
         char *s;
 
+        assert(dev);
+
         /* shortcut, if we are called directly for a "usb_device" type */
         if (udev_device_get_devtype(dev) != NULL && streq(udev_device_get_devtype(dev), "usb_device")) {
                 dev_if_packed_info(dev, packed_if_str, sizeof(packed_if_str));
index a5c3edb..3488ff3 100644 (file)
@@ -119,6 +119,8 @@ size_t udev_event_apply_format(struct udev_event *event, const char *src, char *
         char *s;
         size_t l;
 
+        assert(dev);
+
         from = src;
         s = dest;
         l = size;
index 4262119..c2b20cf 100644 (file)
@@ -664,6 +664,9 @@ static int import_parent_into_properties(struct udev_device *dev, const char *fi
         struct udev_device *dev_parent;
         struct udev_list_entry *list_entry;
 
+        assert(dev);
+        assert(filter);
+
         dev_parent = udev_device_get_parent(dev);
         if (dev_parent == NULL)
                 return -1;
index 34e88af..056cf8c 100644 (file)
@@ -401,6 +401,8 @@ static void worker_spawn(Manager *manager, struct event *event) {
                         struct udev_event *udev_event;
                         int fd_lock = -1;
 
+                        assert(dev);
+
                         log_debug("seq %llu running", udev_device_get_seqnum(dev));
                         udev_event = udev_event_new(dev);
                         if (udev_event == NULL) {