diff options
author | Juergen Gross <jgross@suse.com> | 2016-10-31 09:58:41 -0400 |
---|---|---|
committer | Juergen Gross <jgross@suse.com> | 2016-11-07 07:55:22 -0500 |
commit | f95842e7a9f235ef3b7d6d4b70fee2244149f1e7 (patch) | |
tree | 6a7ac56dd31f72dfd48e563d0b72bb7990441b58 /drivers/net/xen-netback | |
parent | 81362c6f159dcb59fadd60927aa00497d715ca80 (diff) |
xen: make use of xenbus_read_unsigned() in xen-netback
Use xenbus_read_unsigned() instead of xenbus_scanf() when possible.
This requires to change the type of some reads from int to unsigned,
but these cases have been wrong before: negative values are not allowed
for the modified cases.
Cc: wei.liu2@citrix.com
Cc: paul.durrant@citrix.com
Cc: netdev@vger.kernel.org
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Paul Durrant <paul.durrant@citrix.com>
Acked-by: David Vrabel <david.vrabel@citrix.com>
Diffstat (limited to 'drivers/net/xen-netback')
-rw-r--r-- | drivers/net/xen-netback/xenbus.c | 50 |
1 files changed, 14 insertions, 36 deletions
diff --git a/drivers/net/xen-netback/xenbus.c b/drivers/net/xen-netback/xenbus.c index 8674e188b697..7356e00fac54 100644 --- a/drivers/net/xen-netback/xenbus.c +++ b/drivers/net/xen-netback/xenbus.c | |||
@@ -785,12 +785,9 @@ static void xen_mcast_ctrl_changed(struct xenbus_watch *watch, | |||
785 | struct xenvif *vif = container_of(watch, struct xenvif, | 785 | struct xenvif *vif = container_of(watch, struct xenvif, |
786 | mcast_ctrl_watch); | 786 | mcast_ctrl_watch); |
787 | struct xenbus_device *dev = xenvif_to_xenbus_device(vif); | 787 | struct xenbus_device *dev = xenvif_to_xenbus_device(vif); |
788 | int val; | ||
789 | 788 | ||
790 | if (xenbus_scanf(XBT_NIL, dev->otherend, | 789 | vif->multicast_control = !!xenbus_read_unsigned(dev->otherend, |
791 | "request-multicast-control", "%d", &val) < 0) | 790 | "request-multicast-control", 0); |
792 | val = 0; | ||
793 | vif->multicast_control = !!val; | ||
794 | } | 791 | } |
795 | 792 | ||
796 | static int xen_register_mcast_ctrl_watch(struct xenbus_device *dev, | 793 | static int xen_register_mcast_ctrl_watch(struct xenbus_device *dev, |
@@ -934,12 +931,9 @@ static void connect(struct backend_info *be) | |||
934 | /* Check whether the frontend requested multiple queues | 931 | /* Check whether the frontend requested multiple queues |
935 | * and read the number requested. | 932 | * and read the number requested. |
936 | */ | 933 | */ |
937 | err = xenbus_scanf(XBT_NIL, dev->otherend, | 934 | requested_num_queues = xenbus_read_unsigned(dev->otherend, |
938 | "multi-queue-num-queues", | 935 | "multi-queue-num-queues", 1); |
939 | "%u", &requested_num_queues); | 936 | if (requested_num_queues > xenvif_max_queues) { |
940 | if (err < 0) { | ||
941 | requested_num_queues = 1; /* Fall back to single queue */ | ||
942 | } else if (requested_num_queues > xenvif_max_queues) { | ||
943 | /* buggy or malicious guest */ | 937 | /* buggy or malicious guest */ |
944 | xenbus_dev_fatal(dev, err, | 938 | xenbus_dev_fatal(dev, err, |
945 | "guest requested %u queues, exceeding the maximum of %u.", | 939 | "guest requested %u queues, exceeding the maximum of %u.", |
@@ -1134,7 +1128,7 @@ static int read_xenbus_vif_flags(struct backend_info *be) | |||
1134 | struct xenvif *vif = be->vif; | 1128 | struct xenvif *vif = be->vif; |
1135 | struct xenbus_device *dev = be->dev; | 1129 | struct xenbus_device *dev = be->dev; |
1136 | unsigned int rx_copy; | 1130 | unsigned int rx_copy; |
1137 | int err, val; | 1131 | int err; |
1138 | 1132 | ||
1139 | err = xenbus_scanf(XBT_NIL, dev->otherend, "request-rx-copy", "%u", | 1133 | err = xenbus_scanf(XBT_NIL, dev->otherend, "request-rx-copy", "%u", |
1140 | &rx_copy); | 1134 | &rx_copy); |
@@ -1150,10 +1144,7 @@ static int read_xenbus_vif_flags(struct backend_info *be) | |||
1150 | if (!rx_copy) | 1144 | if (!rx_copy) |
1151 | return -EOPNOTSUPP; | 1145 | return -EOPNOTSUPP; |
1152 | 1146 | ||
1153 | if (xenbus_scanf(XBT_NIL, dev->otherend, | 1147 | if (!xenbus_read_unsigned(dev->otherend, "feature-rx-notify", 0)) { |
1154 | "feature-rx-notify", "%d", &val) < 0) | ||
1155 | val = 0; | ||
1156 | if (!val) { | ||
1157 | /* - Reduce drain timeout to poll more frequently for | 1148 | /* - Reduce drain timeout to poll more frequently for |
1158 | * Rx requests. | 1149 | * Rx requests. |
1159 | * - Disable Rx stall detection. | 1150 | * - Disable Rx stall detection. |
@@ -1162,34 +1153,21 @@ static int read_xenbus_vif_flags(struct backend_info *be) | |||
1162 | be->vif->stall_timeout = 0; | 1153 | be->vif->stall_timeout = 0; |
1163 | } | 1154 | } |
1164 | 1155 | ||
1165 | if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-sg", | 1156 | vif->can_sg = !!xenbus_read_unsigned(dev->otherend, "feature-sg", 0); |
1166 | "%d", &val) < 0) | ||
1167 | val = 0; | ||
1168 | vif->can_sg = !!val; | ||
1169 | 1157 | ||
1170 | vif->gso_mask = 0; | 1158 | vif->gso_mask = 0; |
1171 | 1159 | ||
1172 | if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-gso-tcpv4", | 1160 | if (xenbus_read_unsigned(dev->otherend, "feature-gso-tcpv4", 0)) |
1173 | "%d", &val) < 0) | ||
1174 | val = 0; | ||
1175 | if (val) | ||
1176 | vif->gso_mask |= GSO_BIT(TCPV4); | 1161 | vif->gso_mask |= GSO_BIT(TCPV4); |
1177 | 1162 | ||
1178 | if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-gso-tcpv6", | 1163 | if (xenbus_read_unsigned(dev->otherend, "feature-gso-tcpv6", 0)) |
1179 | "%d", &val) < 0) | ||
1180 | val = 0; | ||
1181 | if (val) | ||
1182 | vif->gso_mask |= GSO_BIT(TCPV6); | 1164 | vif->gso_mask |= GSO_BIT(TCPV6); |
1183 | 1165 | ||
1184 | if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-no-csum-offload", | 1166 | vif->ip_csum = !xenbus_read_unsigned(dev->otherend, |
1185 | "%d", &val) < 0) | 1167 | "feature-no-csum-offload", 0); |
1186 | val = 0; | ||
1187 | vif->ip_csum = !val; | ||
1188 | 1168 | ||
1189 | if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-ipv6-csum-offload", | 1169 | vif->ipv6_csum = !!xenbus_read_unsigned(dev->otherend, |
1190 | "%d", &val) < 0) | 1170 | "feature-ipv6-csum-offload", 0); |
1191 | val = 0; | ||
1192 | vif->ipv6_csum = !!val; | ||
1193 | 1171 | ||
1194 | return 0; | 1172 | return 0; |
1195 | } | 1173 | } |