@@ -1129,17 +1129,30 @@ static const struct file_operations umad_sm_fops = {
1129
1129
.llseek = no_llseek ,
1130
1130
};
1131
1131
1132
+ static struct ib_umad_port * get_port (struct ib_device * ibdev ,
1133
+ struct ib_umad_device * umad_dev ,
1134
+ unsigned int port )
1135
+ {
1136
+ if (!umad_dev )
1137
+ return ERR_PTR (- EOPNOTSUPP );
1138
+ if (!rdma_is_port_valid (ibdev , port ))
1139
+ return ERR_PTR (- EINVAL );
1140
+ if (!rdma_cap_ib_mad (ibdev , port ))
1141
+ return ERR_PTR (- EOPNOTSUPP );
1142
+
1143
+ return & umad_dev -> ports [port - rdma_start_port (ibdev )];
1144
+ }
1145
+
1132
1146
static int ib_umad_get_nl_info (struct ib_device * ibdev , void * client_data ,
1133
1147
struct ib_client_nl_info * res )
1134
1148
{
1135
- struct ib_umad_device * umad_dev = client_data ;
1149
+ struct ib_umad_port * port = get_port ( ibdev , client_data , res -> port ) ;
1136
1150
1137
- if (! rdma_is_port_valid ( ibdev , res -> port ))
1138
- return - EINVAL ;
1151
+ if (IS_ERR ( port ))
1152
+ return PTR_ERR ( port ) ;
1139
1153
1140
1154
res -> abi = IB_USER_MAD_ABI_VERSION ;
1141
- res -> cdev = & umad_dev -> ports [res -> port - rdma_start_port (ibdev )].dev ;
1142
-
1155
+ res -> cdev = & port -> dev ;
1143
1156
return 0 ;
1144
1157
}
1145
1158
@@ -1154,15 +1167,13 @@ MODULE_ALIAS_RDMA_CLIENT("umad");
1154
1167
static int ib_issm_get_nl_info (struct ib_device * ibdev , void * client_data ,
1155
1168
struct ib_client_nl_info * res )
1156
1169
{
1157
- struct ib_umad_device * umad_dev =
1158
- ib_get_client_data (ibdev , & umad_client );
1170
+ struct ib_umad_port * port = get_port (ibdev , client_data , res -> port );
1159
1171
1160
- if (! rdma_is_port_valid ( ibdev , res -> port ))
1161
- return - EINVAL ;
1172
+ if (IS_ERR ( port ))
1173
+ return PTR_ERR ( port ) ;
1162
1174
1163
1175
res -> abi = IB_USER_MAD_ABI_VERSION ;
1164
- res -> cdev = & umad_dev -> ports [res -> port - rdma_start_port (ibdev )].sm_dev ;
1165
-
1176
+ res -> cdev = & port -> sm_dev ;
1166
1177
return 0 ;
1167
1178
}
1168
1179
0 commit comments