[PATCH] Check port number in query_port/modify_port (was: [openib-general] some bugs that can be found using the gen2_basic in the contrib/m ellanox folder)

Roland Dreier rolandd at cisco.com
Mon Oct 3 09:32:40 PDT 2005


I feel silly for spending time on this, but I made this change to make
a couple of your tests pass:

 - R.

--- infiniband/core/device.c	(revision 3613)
+++ infiniband/core/device.c	(working copy)
@@ -514,6 +514,12 @@ int ib_query_port(struct ib_device *devi
 		  u8 port_num,
 		  struct ib_port_attr *port_attr)
 {
+	if (device->node_type == IB_NODE_SWITCH) {
+		if (port_num)
+			return -EINVAL;
+	} else if (port_num < 1 || port_num > device->phys_port_cnt)
+		return -EINVAL;
+
 	return device->query_port(device, port_num, port_attr);
 }
 EXPORT_SYMBOL(ib_query_port);
@@ -583,6 +589,12 @@ int ib_modify_port(struct ib_device *dev
 		   u8 port_num, int port_modify_mask,
 		   struct ib_port_modify *port_modify)
 {
+	if (device->node_type == IB_NODE_SWITCH) {
+		if (port_num)
+			return -EINVAL;
+	} else if (port_num < 1 || port_num > device->phys_port_cnt)
+		return -EINVAL;
+
 	return device->modify_port(device, port_num, port_modify_mask,
 				   port_modify);
 }



More information about the general mailing list