]> xenbits.xensource.com Git - people/royger/linux-2.6.18-xen.git/commitdiff
xenbus: xenbus_gather()/xenbus_scanf() usage adjustments
authorJan Beulcih <jbeulich@novell.com>
Thu, 23 Jun 2011 10:13:16 +0000 (11:13 +0100)
committerJan Beulcih <jbeulich@novell.com>
Thu, 23 Jun 2011 10:13:16 +0000 (11:13 +0100)
- don't use xenbus_gather() for just a single, non-string item (as it
  doesn't do format checking on its inputs)
- grant references don't need to be parsed as "long", since
  grant_ref_t
  is a typedef of uint32_t
- in the frontend protocol determination logic in blkback and blktap,
  don't parse into a local buffer - use the allocated string directly

Signed-off-by: Jan Beulich <jbeulich@novell.com>
drivers/xen/blkback/xenbus.c
drivers/xen/blkfront/blkfront.c
drivers/xen/blktap/xenbus.c
drivers/xen/core/reboot.c
drivers/xen/netback/xenbus.c
drivers/xen/scsiback/xenbus.c
drivers/xen/tpmback/xenbus.c
drivers/xen/usbback/xenbus.c
drivers/xen/xenbus/xenbus_client.c
drivers/xen/xenbus/xenbus_probe.c

index 4f2c0dd0b46515fb604a25dea8b0f4f62680fb17..ed75cdd7c46328868403ecff76e932760a813b22 100644 (file)
@@ -485,14 +485,13 @@ again:
 static int connect_ring(struct backend_info *be)
 {
        struct xenbus_device *dev = be->dev;
-       unsigned long ring_ref;
-       unsigned int evtchn;
-       char protocol[64] = "";
+       unsigned int ring_ref, evtchn;
+       char *protocol;
        int err;
 
        DPRINTK("%s", dev->otherend);
 
-       err = xenbus_gather(XBT_NIL, dev->otherend, "ring-ref", "%lu", &ring_ref,
+       err = xenbus_gather(XBT_NIL, dev->otherend, "ring-ref", "%u", &ring_ref,
                            "event-channel", "%u", &evtchn, NULL);
        if (err) {
                xenbus_dev_fatal(dev, err,
@@ -503,9 +502,9 @@ static int connect_ring(struct backend_info *be)
 
        be->blkif->blk_protocol = BLKIF_PROTOCOL_NATIVE;
        err = xenbus_gather(XBT_NIL, dev->otherend, "protocol",
-                           "%63s", protocol, NULL);
+                           NULL, &protocol, NULL);
        if (err)
-               strcpy(protocol, "unspecified, assuming native");
+               protocol = NULL;
        else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_NATIVE))
                be->blkif->blk_protocol = BLKIF_PROTOCOL_NATIVE;
        else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_X86_32))
@@ -514,16 +513,19 @@ static int connect_ring(struct backend_info *be)
                be->blkif->blk_protocol = BLKIF_PROTOCOL_X86_64;
        else {
                xenbus_dev_fatal(dev, err, "unknown fe protocol %s", protocol);
+               kfree(protocol);
                return -1;
        }
        printk(KERN_INFO
-              "blkback: ring-ref %ld, event-channel %d, protocol %d (%s)\n",
-              ring_ref, evtchn, be->blkif->blk_protocol, protocol);
+              "blkback: ring-ref %u, event-channel %u, protocol %d (%s)\n",
+              ring_ref, evtchn, be->blkif->blk_protocol,
+              protocol ?: "unspecified, assuming native");
+       kfree(protocol);
 
        /* Map the shared frame, irq etc. */
        err = blkif_map(be->blkif, ring_ref, evtchn);
        if (err) {
-               xenbus_dev_fatal(dev, err, "mapping ring-ref %lu port %u",
+               xenbus_dev_fatal(dev, err, "mapping ring-ref %u port %u",
                                 ring_ref, evtchn);
                return err;
        }
index 92d9776136548396592a3ea110b36976d15ff3b9..617c74783abc775e9cef1795ee2414107825e6d3 100644 (file)
@@ -334,7 +334,7 @@ static void connect(struct blkfront_info *info)
                 */
                err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
                                   "sectors", "%Lu", &sectors);
-               if (XENBUS_EXIST_ERR(err))
+               if (err != 1)
                        return;
                printk(KERN_INFO "Setting capacity to %Lu\n",
                       sectors);
@@ -359,10 +359,9 @@ static void connect(struct blkfront_info *info)
                return;
        }
 
-       err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
-                           "feature-barrier", "%d", &info->feature_barrier,
-                           NULL);
-       if (err)
+       err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
+                          "feature-barrier", "%d", &info->feature_barrier);
+       if (err <= 0)
                info->feature_barrier = 0;
 
        err = xlvbd_add(sectors, info->vdevice, binfo, sector_size, info);
index 922ace747894e4c3e6a01a4e649efc601c55660b..74e2a81a60d56d1a401aa9e3b55932cba2330d0d 100644 (file)
@@ -319,7 +319,7 @@ static void tap_backend_changed(struct xenbus_watch *watch,
         * and disk info to xenstore
         */
        err = xenbus_gather(XBT_NIL, dev->nodename, "info", "%lu", &info, 
-                           NULL);
+                           "sectors", "%Lu", &be->blkif->sectors, NULL);
        if (XENBUS_EXIST_ERR(err))
                return;
        if (err) {
@@ -329,9 +329,6 @@ static void tap_backend_changed(struct xenbus_watch *watch,
 
        DPRINTK("Userspace update on disk info, %lu\n",info);
 
-       err = xenbus_gather(XBT_NIL, dev->nodename, "sectors", "%llu", 
-                           &be->blkif->sectors, NULL);
-
        /* Associate tap dev with domid*/
        be->blkif->dev_num = dom_to_devid(be->blkif->domid, be->xenbus_id, 
                                          be->blkif);
@@ -436,14 +433,13 @@ static void connect(struct backend_info *be)
 static int connect_ring(struct backend_info *be)
 {
        struct xenbus_device *dev = be->dev;
-       unsigned long ring_ref;
-       unsigned int evtchn;
-       char protocol[64];
+       unsigned int ring_ref, evtchn;
+       char *protocol;
        int err;
 
        DPRINTK("%s\n", dev->otherend);
 
-       err = xenbus_gather(XBT_NIL, dev->otherend, "ring-ref", "%lu", 
+       err = xenbus_gather(XBT_NIL, dev->otherend, "ring-ref", "%u",
                            &ring_ref, "event-channel", "%u", &evtchn, NULL);
        if (err) {
                xenbus_dev_fatal(dev, err,
@@ -454,9 +450,9 @@ static int connect_ring(struct backend_info *be)
 
        be->blkif->blk_protocol = BLKIF_PROTOCOL_NATIVE;
        err = xenbus_gather(XBT_NIL, dev->otherend, "protocol",
-                           "%63s", protocol, NULL);
+                           NULL, &protocol, NULL);
        if (err)
-               strcpy(protocol, "unspecified, assuming native");
+               protocol = NULL;
        else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_NATIVE))
                be->blkif->blk_protocol = BLKIF_PROTOCOL_NATIVE;
        else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_X86_32))
@@ -465,16 +461,19 @@ static int connect_ring(struct backend_info *be)
                be->blkif->blk_protocol = BLKIF_PROTOCOL_X86_64;
        else {
                xenbus_dev_fatal(dev, err, "unknown fe protocol %s", protocol);
+               kfree(protocol);
                return -1;
        }
        printk(KERN_INFO
-              "blktap: ring-ref %ld, event-channel %d, protocol %d (%s)\n",
-              ring_ref, evtchn, be->blkif->blk_protocol, protocol);
+              "blktap: ring-ref %u, event-channel %u, protocol %d (%s)\n",
+              ring_ref, evtchn, be->blkif->blk_protocol,
+              protocol ?: "unspecified, assuming native");
+       kfree(protocol);
 
        /* Map the shared frame, irq etc. */
        err = tap_blkif_map(be->blkif, dev, ring_ref, evtchn);
        if (err) {
-               xenbus_dev_fatal(dev, err, "mapping ring-ref %lu port %u",
+               xenbus_dev_fatal(dev, err, "mapping ring-ref %u port %u",
                                 ring_ref, evtchn);
                return err;
        } 
index 51ae7d8175bae7c340c90c514d3292e08e3ca2e1..0ea4a693c0d9ede3455144f9036e8708a83bbef9 100644 (file)
@@ -215,7 +215,7 @@ static void sysrq_handler(struct xenbus_watch *watch, const char **vec,
        err = xenbus_transaction_start(&xbt);
        if (err)
                return;
-       if (!xenbus_scanf(xbt, "control", "sysrq", "%c", &sysrq_key)) {
+       if (xenbus_scanf(xbt, "control", "sysrq", "%c", &sysrq_key) <= 0) {
                printk(KERN_ERR "Unable to read sysrq code in "
                       "control/sysrq\n");
                xenbus_transaction_end(xbt, 1);
index 00ce7340a194f57a4d15ce4f135d3d2d7cec6f2d..7223859cb3333ddbee0771101d4ac0e78a35a67e 100644 (file)
@@ -358,7 +358,7 @@ static int connect_rings(struct backend_info *be)
 {
        netif_t *netif = be->netif;
        struct xenbus_device *dev = be->dev;
-       unsigned long tx_ring_ref, rx_ring_ref;
+       unsigned int tx_ring_ref, rx_ring_ref;
        unsigned int evtchn, rx_copy;
        int err;
        int val;
@@ -366,8 +366,8 @@ static int connect_rings(struct backend_info *be)
        DPRINTK("");
 
        err = xenbus_gather(XBT_NIL, dev->otherend,
-                           "tx-ring-ref", "%lu", &tx_ring_ref,
-                           "rx-ring-ref", "%lu", &rx_ring_ref,
+                           "tx-ring-ref", "%u", &tx_ring_ref,
+                           "rx-ring-ref", "%u", &rx_ring_ref,
                            "event-channel", "%u", &evtchn, NULL);
        if (err) {
                xenbus_dev_fatal(dev, err,
@@ -421,7 +421,7 @@ static int connect_rings(struct backend_info *be)
        err = netif_map(be, tx_ring_ref, rx_ring_ref, evtchn);
        if (err) {
                xenbus_dev_fatal(dev, err,
-                                "mapping shared-frames %lu/%lu port %u",
+                                "mapping shared-frames %u/%u port %u",
                                 tx_ring_ref, rx_ring_ref, evtchn);
                return err;
        }
index 5f8e3459d2058fd20c0ffc28f5f0b7e96525fd97..9a2492f67c15e6b6aae7ddd6a9db74eec402ccc5 100644 (file)
@@ -60,13 +60,12 @@ static int __vscsiif_name(struct backend_info *be, char *buf)
 static int scsiback_map(struct backend_info *be)
 {
        struct xenbus_device *dev = be->dev;
-       unsigned long ring_ref;
-       unsigned int evtchn;
+       unsigned int ring_ref, evtchn;
        int err;
        char name[TASK_COMM_LEN];
 
        err = xenbus_gather(XBT_NIL, dev->otherend,
-                       "ring-ref", "%lu", &ring_ref,
+                       "ring-ref", "%u", &ring_ref,
                        "event-channel", "%u", &evtchn, NULL);
        if (err) {
                xenbus_dev_fatal(dev, err, "reading %s ring", dev->otherend);
index e0f6167ac15b0bcb4a2687db33de4fd67ac72f43..6f3b02404792372c0d16d4bf62eabc21f507ad0a 100644 (file)
@@ -210,12 +210,11 @@ abort:
 static int connect_ring(struct backend_info *be)
 {
        struct xenbus_device *dev = be->dev;
-       unsigned long ring_ref;
-       unsigned int evtchn;
+       unsigned int ring_ref, evtchn;
        int err;
 
        err = xenbus_gather(XBT_NIL, dev->otherend,
-                           "ring-ref", "%lu", &ring_ref,
+                           "ring-ref", "%u", &ring_ref,
                            "event-channel", "%u", &evtchn, NULL);
        if (err) {
                xenbus_dev_error(dev, err,
@@ -238,7 +237,7 @@ static int connect_ring(struct backend_info *be)
                err = tpmif_map(be->tpmif, ring_ref, evtchn);
                if (err) {
                        xenbus_dev_error(dev, err,
-                                        "mapping shared-frame %lu port %u",
+                                        "mapping shared-frame %u port %u",
                                         ring_ref, evtchn);
                        return err;
                }
index 34156675251b174c1c394e8915eb83b4174e7e7c..1daf39e10f284ab11d3727ee21ae50485ba6ac6b 100644 (file)
@@ -226,14 +226,12 @@ fail:
 static int connect_rings(usbif_t *usbif)
 {
        struct xenbus_device *dev = usbif->xbdev;
-       unsigned long urb_ring_ref;
-       unsigned long conn_ring_ref;
-       unsigned int evtchn;
+       unsigned int urb_ring_ref, conn_ring_ref, evtchn;
        int err;
 
        err = xenbus_gather(XBT_NIL, dev->otherend,
-                           "urb-ring-ref", "%lu", &urb_ring_ref,
-                           "conn-ring-ref", "%lu", &conn_ring_ref,
+                           "urb-ring-ref", "%u", &urb_ring_ref,
+                           "conn-ring-ref", "%u", &conn_ring_ref,
                            "event-channel", "%u", &evtchn, NULL);
        if (err) {
                xenbus_dev_fatal(dev, err,
@@ -242,13 +240,14 @@ static int connect_rings(usbif_t *usbif)
                return err;
        }
 
-       printk("usbback: urb-ring-ref %ld, conn-ring-ref %ld, event-channel %d\n",
+       printk("usbback: urb-ring-ref %u, conn-ring-ref %u,"
+              " event-channel %u\n",
               urb_ring_ref, conn_ring_ref, evtchn);
 
        err = usbif_map(usbif, urb_ring_ref, conn_ring_ref, evtchn);
        if (err) {
                xenbus_dev_fatal(dev, err,
-                               "mapping urb-ring-ref %lu conn-ring-ref %lu port %u",
+                               "mapping urb-ring-ref %u conn-ring-ref %u port %u",
                                urb_ring_ref, conn_ring_ref, evtchn);
                return err;
        }
index 3b0bf33e693cae4aa6cd56bcc717c294a7342170..a48868a4b753154aacb5793ccb18475ed3ae4526 100644 (file)
@@ -276,9 +276,9 @@ EXPORT_SYMBOL_GPL(xenbus_free_evtchn);
 
 enum xenbus_state xenbus_read_driver_state(const char *path)
 {
-       enum xenbus_state result;
-       int err = xenbus_gather(XBT_NIL, path, "state", "%d", &result, NULL);
-       if (err)
+       int result;
+
+       if (xenbus_scanf(XBT_NIL, path, "state", "%d", &result) != 1)
                result = XenbusStateUnknown;
 
        return result;
index 33afc966faaf0a3e5afccfc2d13d7cb344411784..9352e8b9a2733d5b7d1e79d6a29bf7b899b36bc5 100644 (file)
@@ -865,7 +865,8 @@ static int be_state;
 
 static void xenbus_reset_state_changed(struct xenbus_watch *w, const char **v, unsigned int l)
 {
-       xenbus_scanf(XBT_NIL, v[XS_WATCH_PATH], "", "%i", &be_state);
+       if (xenbus_scanf(XBT_NIL, v[XS_WATCH_PATH], "", "%i", &be_state) != 1)
+               be_state = XenbusStateUnknown;
        printk(KERN_INFO "XENBUS: %s %s\n", v[XS_WATCH_PATH], xenbus_strstate(be_state));
        wake_up(&be_state_wq);
 }