Skip to content

Commit 3624a8f

Browse files
jgunthorpedledford
authored andcommitted
RDMA/uverbs: Use an unambiguous errno for method not supported
Returning EOPNOTSUPP is problematic because it can also be returned by the method function, and we use it in quite a few places in drivers these days. Instead, dedicate EPROTONOSUPPORT to indicate that the ioctl framework is enabled but the requested object and method are not supported by the kernel. No other case will return this code, and it lets userspace know to fall back to write(). grep says we do not use it today in drivers/infiniband subsystem. Signed-off-by: Jason Gunthorpe <[email protected]> Reviewed-by: Matan Barak <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent f2fe3c4 commit 3624a8f

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

drivers/infiniband/core/uverbs_ioctl.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,13 @@ static long ib_uverbs_cmd_verbs(struct ib_device *ib_dev,
243243
size_t ctx_size;
244244
uintptr_t data[UVERBS_OPTIMIZE_USING_STACK_SZ / sizeof(uintptr_t)];
245245

246-
if (hdr->reserved)
247-
return -EINVAL;
248-
249246
object_spec = uverbs_get_object(ib_dev, hdr->object_id);
250247
if (!object_spec)
251-
return -EOPNOTSUPP;
248+
return -EPROTONOSUPPORT;
252249

253250
method_spec = uverbs_get_method(object_spec, hdr->method_id);
254251
if (!method_spec)
255-
return -EOPNOTSUPP;
252+
return -EPROTONOSUPPORT;
256253

257254
if ((method_spec->flags & UVERBS_ACTION_FLAG_CREATE_ROOT) ^ !file->ucontext)
258255
return -EINVAL;
@@ -305,6 +302,16 @@ static long ib_uverbs_cmd_verbs(struct ib_device *ib_dev,
305302

306303
err = uverbs_handle_method(buf, ctx->uattrs, hdr->num_attrs, ib_dev,
307304
file, method_spec, ctx->uverbs_attr_bundle);
305+
306+
/*
307+
* EPROTONOSUPPORT is ONLY to be returned if the ioctl framework can
308+
* not invoke the method because the request is not supported. No
309+
* other cases should return this code.
310+
*/
311+
if (unlikely(err == -EPROTONOSUPPORT)) {
312+
WARN_ON_ONCE(err == -EPROTONOSUPPORT);
313+
err = -EINVAL;
314+
}
308315
out:
309316
if (ctx != (void *)data)
310317
kfree(ctx);
@@ -341,7 +348,7 @@ long ib_uverbs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
341348
}
342349

343350
if (hdr.reserved) {
344-
err = -EOPNOTSUPP;
351+
err = -EPROTONOSUPPORT;
345352
goto out;
346353
}
347354

0 commit comments

Comments
 (0)