- if (add)
- ret = main_dev->hotplug_ops->add(main_dev, dev);
- else
- ret = main_dev->hotplug_ops->del(main_dev, dev);
+ dev = device_get(blobmsg_data(tb[DEV_NAME]), add);
+ if (!dev)
+ return UBUS_STATUS_NOT_FOUND;
+
+ if (main_dev != dev) {
+ if (add)
+ ret = main_dev->hotplug_ops->add(main_dev, dev);
+ else
+ ret = main_dev->hotplug_ops->del(main_dev, dev);
+ if (ret)
+ ret = UBUS_STATUS_UNKNOWN_ERROR;
+ } else {
+ ret = UBUS_STATUS_INVALID_ARGUMENT;
+ }