浏览代码

IB/ipath: Clean up handling of GUID 0

Respond with an error to the SM if our GUID is 0, and don't allow the
user to set our GUID to 0.

Signed-off-by: Bryan O'Sullivan <bryan.osullivan@qlogic.com>
Signed-off-by: Roland Dreier <rolandd@cisco.com>
Bryan O'Sullivan 18 年之前
父节点
当前提交
11b054fe1d
共有 2 个文件被更改,包括 17 次插入8 次删除
  1. 11 5
      drivers/infiniband/hw/ipath/ipath_mad.c
  2. 6 3
      drivers/infiniband/hw/ipath/ipath_sysfs.c

+ 11 - 5
drivers/infiniband/hw/ipath/ipath_mad.c

@@ -87,7 +87,8 @@ static int recv_subn_get_nodeinfo(struct ib_smp *smp,
 	struct ipath_devdata *dd = to_idev(ibdev)->dd;
 	struct ipath_devdata *dd = to_idev(ibdev)->dd;
 	u32 vendor, majrev, minrev;
 	u32 vendor, majrev, minrev;
 
 
-	if (smp->attr_mod)
+	/* GUID 0 is illegal */
+	if (smp->attr_mod || (dd->ipath_guid == 0))
 		smp->status |= IB_SMP_INVALID_FIELD;
 		smp->status |= IB_SMP_INVALID_FIELD;
 
 
 	nip->base_version = 1;
 	nip->base_version = 1;
@@ -131,10 +132,15 @@ static int recv_subn_get_guidinfo(struct ib_smp *smp,
 	 * We only support one GUID for now.  If this changes, the
 	 * We only support one GUID for now.  If this changes, the
 	 * portinfo.guid_cap field needs to be updated too.
 	 * portinfo.guid_cap field needs to be updated too.
 	 */
 	 */
-	if (startgx == 0)
-		/* The first is a copy of the read-only HW GUID. */
-		*p = to_idev(ibdev)->dd->ipath_guid;
-	else
+	if (startgx == 0) {
+		__be64 g = to_idev(ibdev)->dd->ipath_guid;
+		if (g == 0)
+			/* GUID 0 is illegal */
+			smp->status |= IB_SMP_INVALID_FIELD;
+		else
+			/* The first is a copy of the read-only HW GUID. */
+			*p = g;
+	} else
 		smp->status |= IB_SMP_INVALID_FIELD;
 		smp->status |= IB_SMP_INVALID_FIELD;
 
 
 	return reply(smp);
 	return reply(smp);

+ 6 - 3
drivers/infiniband/hw/ipath/ipath_sysfs.c

@@ -257,7 +257,7 @@ static ssize_t store_guid(struct device *dev,
 	struct ipath_devdata *dd = dev_get_drvdata(dev);
 	struct ipath_devdata *dd = dev_get_drvdata(dev);
 	ssize_t ret;
 	ssize_t ret;
 	unsigned short guid[8];
 	unsigned short guid[8];
-	__be64 nguid;
+	__be64 new_guid;
 	u8 *ng;
 	u8 *ng;
 	int i;
 	int i;
 
 
@@ -266,7 +266,7 @@ static ssize_t store_guid(struct device *dev,
 		   &guid[4], &guid[5], &guid[6], &guid[7]) != 8)
 		   &guid[4], &guid[5], &guid[6], &guid[7]) != 8)
 		goto invalid;
 		goto invalid;
 
 
-	ng = (u8 *) &nguid;
+	ng = (u8 *) &new_guid;
 
 
 	for (i = 0; i < 8; i++) {
 	for (i = 0; i < 8; i++) {
 		if (guid[i] > 0xff)
 		if (guid[i] > 0xff)
@@ -274,7 +274,10 @@ static ssize_t store_guid(struct device *dev,
 		ng[i] = guid[i];
 		ng[i] = guid[i];
 	}
 	}
 
 
-	dd->ipath_guid = nguid;
+	if (new_guid == 0)
+		goto invalid;
+
+	dd->ipath_guid = new_guid;
 	dd->ipath_nguid = 1;
 	dd->ipath_nguid = 1;
 
 
 	ret = strlen(buf);
 	ret = strlen(buf);