[openib-general] [PATCH] mad_rmpp: Fix receive length calculation

Hal Rosenstock halr at voltaire.com
Tue Sep 20 14:53:25 PDT 2005


mad_rmpp: Fix receive length calculation

Signed-off-by: Hal Rosenstock <halr at voltaire.com>

Index: mad_rmpp.c
===================================================================
--- mad_rmpp.c	(revision 3496)
+++ mad_rmpp.c	(working copy)
@@ -407,13 +407,23 @@ static inline int get_mad_len(struct mad
 {
 	struct ib_rmpp_mad *rmpp_mad;
 	int hdr_size, data_size, pad;
+	int class_hdr_len = 0;
+	u8 mgmt_class;
 
 	rmpp_mad = (struct ib_rmpp_mad *)rmpp_recv->cur_seg_buf->mad;
+	mgmt_class = rmpp_mad->mad_hdr.mgmt_class;
 
-	hdr_size = data_offset(rmpp_mad->mad_hdr.mgmt_class);
+	hdr_size = data_offset(mgmt_class);
 	data_size = sizeof(struct ib_rmpp_mad) - hdr_size;
 	pad = data_size - be32_to_cpu(rmpp_mad->rmpp_hdr.paylen_newwin);
-	if (pad > data_size || pad < 0)
+	/* Adjust pad by one class header size */
+	if (mgmt_class == IB_MGMT_CLASS_SUBN_ADM)
+		class_hdr_len = sizeof(struct ib_sa_hdr);
+	else if ((mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START) &&
+		 (mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END))
+		class_hdr_len = 4;
+	pad += class_hdr_len;
+	if (pad > data_size + class_hdr_len || pad < 0)
 		pad = 0;
 
 	return hdr_size + rmpp_recv->seg_num * data_size - pad;






More information about the general mailing list