static int dev_show(struct rd *rd)
{
- struct dev_map *dev_map;
- int ret = 0;
-
- if (rd->json_output)
- jsonw_start_array(rd->jw);
- if (rd_no_arg(rd)) {
- list_for_each_entry(dev_map, &rd->dev_map_list, list) {
- rd->dev_idx = dev_map->idx;
- ret = dev_one_show(rd);
- if (ret)
- goto out;
- }
- } else {
- dev_map = dev_map_lookup(rd, false);
- if (!dev_map) {
- pr_err("Wrong device name\n");
- ret = -ENOENT;
- goto out;
- }
- rd_arg_inc(rd);
- rd->dev_idx = dev_map->idx;
- ret = dev_one_show(rd);
- }
-out:
- if (rd->json_output)
- jsonw_end_array(rd->jw);
- return ret;
+ return rd_exec_dev(rd, dev_one_show);
}
int cmd_dev(struct rd *rd)
int cmd_dev(struct rd *rd);
int cmd_link(struct rd *rd);
int rd_exec_cmd(struct rd *rd, const struct rd_cmd *c, const char *str);
+int rd_exec_dev(struct rd *rd, int (*cb)(struct rd *rd));
/*
* Device manipulation
dev_map_cleanup(rd);
}
+int rd_exec_dev(struct rd *rd, int (*cb)(struct rd *rd))
+{
+ struct dev_map *dev_map;
+ int ret = 0;
+
+ if (rd->json_output)
+ jsonw_start_array(rd->jw);
+ if (rd_no_arg(rd)) {
+ list_for_each_entry(dev_map, &rd->dev_map_list, list) {
+ rd->dev_idx = dev_map->idx;
+ ret = cb(rd);
+ if (ret)
+ goto out;
+ }
+ } else {
+ dev_map = dev_map_lookup(rd, false);
+ if (!dev_map) {
+ pr_err("Wrong device name\n");
+ ret = -ENOENT;
+ goto out;
+ }
+ rd_arg_inc(rd);
+ rd->dev_idx = dev_map->idx;
+ ret = cb(rd);
+ }
+out:
+ if (rd->json_output)
+ jsonw_end_array(rd->jw);
+ return ret;
+}
+
int rd_exec_cmd(struct rd *rd, const struct rd_cmd *cmds, const char *str)
{
const struct rd_cmd *c;