Advertisement
Guest User

Untitled

a guest
Mar 25th, 2021
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 16.04 KB | None | 0 0
  1. Date: Fri, 25 Jan 2019 13:17:38 -0700
  2. Subject: [PATCH] Disable logging by default and clarified reading back of
  3.  state
  4.  
  5. Updated to use driver instead of device
  6. ---
  7. arch/arm/mach-imx/mu.c           |  26 +++++---
  8.  drivers/rpmsg/imx_rpmsg.c        |  26 +++++---
  9.  drivers/rpmsg/imx_rpmsg_tty.c    |  29 +++++---
  10.  drivers/rpmsg/virtio_rpmsg_bus.c | 139 ++++++++++++++++++---------------------
  11.  4 files changed, 120 insertions(+), 100 deletions(-)
  12.  
  13. diff --git a/arch/arm/mach-imx/mu.c b/arch/arm/mach-imx/mu.c
  14. index a962b44..201528b 100644
  15. --- a/arch/arm/mach-imx/mu.c
  16. +++ b/arch/arm/mach-imx/mu.c
  17. @@ -65,7 +65,7 @@ struct irq_domain *domain;
  18.  static bool m4_in_stop;
  19.  static struct clk *clk;
  20.  static DEFINE_SPINLOCK(mu_lock);
  21. -static bool logging_enabled = true;
  22. +static bool logging_enabled = false;
  23.  
  24.  void imx_mu_set_m4_run_mode(void)
  25.  {
  26. @@ -478,15 +478,25 @@ static int imx_mu_probe(struct platform_device *pdev)
  27.     return 0;
  28.  }
  29.  
  30. -static ssize_t show_log_level(struct device* dev, struct device_attribute* attr, char* buf)
  31. +static ssize_t show_log_level(struct device_driver * dev, char* buf)
  32.  {
  33. -        return scnprintf(buf, PAGE_SIZE, "%s\n", logging_enabled ? "0" : "1");
  34. +        return scnprintf(buf, PAGE_SIZE, "%s\n", logging_enabled ? "1 - on" : "0 - off");
  35.  }
  36.  
  37. -static ssize_t toggle_log_level(struct device* dev, struct device_attribute* attr, const char* buf, size_t count)
  38. +static ssize_t toggle_log_level(struct device_driver * dev, const char* buf, size_t count)
  39.  {
  40. -         logging_enabled = logging_enabled ? false : true;
  41. -         return count;
  42. +   if(buf && count > 0)
  43. +   {
  44. +       if(buf[0] == '1')
  45. +       {
  46. +           logging_enabled = true;
  47. +       }
  48. +       else
  49. +       {
  50. +           logging_enabled = false;
  51. +       }
  52. +   }
  53. +    return count;
  54.  }
  55.  
  56.  static const struct of_device_id imx_mu_ids[] = {
  57. @@ -496,9 +506,9 @@ static const struct of_device_id imx_mu_ids[] = {
  58.     { }
  59.  };
  60.  
  61. -static DEVICE_ATTR(log_enabled, 0644, show_log_level, toggle_log_level);
  62. +static DRIVER_ATTR(log_enabled, 0644, show_log_level, toggle_log_level);
  63.  static struct attribute* dev_attrs[] = {
  64. -  &dev_attr_log_enabled.attr,
  65. +  &driver_attr_log_enabled.attr,
  66.    NULL,
  67.  };
  68.  static struct attribute_group dev_attr_group = {
  69. diff --git a/drivers/rpmsg/imx_rpmsg.c b/drivers/rpmsg/imx_rpmsg.c
  70. index b84601a..041f542 100644
  71. --- a/drivers/rpmsg/imx_rpmsg.c
  72. +++ b/drivers/rpmsg/imx_rpmsg.c
  73. @@ -105,7 +105,7 @@ struct imx_rpmsg_vq_info {
  74.     struct imx_rpmsg_vproc *rpdev;
  75.  };
  76.  
  77. -static bool logging_enabled = true;
  78. +static bool logging_enabled = false;
  79.  
  80.  static u64 imx_rpmsg_get_features(struct virtio_device *vdev)
  81.  {
  82. @@ -551,20 +551,30 @@ static int imx_rpmsg_probe(struct platform_device *pdev)
  83.     return ret;
  84.  }
  85.  
  86. -static ssize_t show_log_level(struct device* dev, struct device_attribute* attr, char* buf)
  87. +static ssize_t show_log_level(struct device_driver * dev, char* buf)
  88.  {
  89. -  return scnprintf(buf, PAGE_SIZE, "%s\n", logging_enabled ? "0" : "1");
  90. +   return scnprintf(buf, PAGE_SIZE, "%s\n", logging_enabled ? "1 - on" : "0 - off");
  91.  }
  92.  
  93. -static ssize_t toggle_log_level(struct device* dev, struct device_attribute* attr, const char* buf, size_t count)
  94. +static ssize_t toggle_log_level(struct device_driver * dev, const char* buf, size_t count)
  95.  {
  96. -  logging_enabled = logging_enabled ? false : true;
  97. -  return count;
  98. +   if(buf && count > 0)
  99. +   {
  100. +       if(buf[0] == '1')
  101. +       {
  102. +           logging_enabled = true;
  103. +       }
  104. +       else
  105. +       {
  106. +           logging_enabled = false;
  107. +       }
  108. +   }
  109. +    return count;
  110.  }
  111.  
  112. -static DEVICE_ATTR(log_enabled, 0644, show_log_level, toggle_log_level);
  113. +static DRIVER_ATTR(log_enabled, 0644, show_log_level, toggle_log_level);
  114.  static struct attribute *dev_attrs[] = {
  115. -  &dev_attr_log_enabled.attr,
  116. +  &driver_attr_log_enabled.attr,
  117.    NULL,
  118.  };
  119.  static struct attribute_group dev_attr_group = {
  120. diff --git a/drivers/rpmsg/imx_rpmsg_tty.c b/drivers/rpmsg/imx_rpmsg_tty.c
  121. index 4503fe0..09640cc 100644
  122. --- a/drivers/rpmsg/imx_rpmsg_tty.c
  123. +++ b/drivers/rpmsg/imx_rpmsg_tty.c
  124. @@ -38,17 +38,27 @@ static struct rpmsgtty_port rpmsg_tty_port;
  125.  #define RPMSG_MAX_SIZE     256
  126.  #define MSG        "hello world!"
  127.  
  128. -static bool logging_enabled = true;
  129. +static bool logging_enabled = false;
  130.  
  131. -static ssize_t show_log_level(struct device* dev, struct device_attribute* attr, char* buf)
  132. +static ssize_t show_log_level(struct device_driver * dev, char* buf)
  133.  {
  134. -        return scnprintf(buf, PAGE_SIZE, "%s\n", logging_enabled ? "0" : "1");
  135. +    return scnprintf(buf, PAGE_SIZE, "%s\n", logging_enabled ? "1 - on" : "0 - off");
  136.  }
  137.  
  138. -static ssize_t toggle_log_level(struct device* dev, struct device_attribute* attr, const char* buf, size_t count)
  139. +static ssize_t toggle_log_level(struct device_driver * dev, const char* buf, size_t count)
  140.  {
  141. -         logging_enabled = logging_enabled ? false : true;
  142. -         return count;
  143. +   if(buf && count > 0)
  144. +   {
  145. +       if(buf[0] == '1')
  146. +       {
  147. +           logging_enabled = true;
  148. +       }
  149. +       else
  150. +       {
  151. +           logging_enabled = false;
  152. +       }
  153. +   }
  154. +    return count;
  155.  }
  156.  
  157.  static int rpmsg_tty_cb(struct rpmsg_device *rpdev, void *data, int len,
  158. @@ -195,8 +205,9 @@ static int rpmsg_tty_probe(struct rpmsg_device *rpdev)
  159.     if (err < 0) {
  160.         pr_err("Couldn't install rpmsg tty driver: err %d\n", err);
  161.         goto error;
  162. -   } else if (logging_enabled)
  163. +   } else if (logging_enabled) {
  164.         pr_info("Install rpmsg tty driver!\n");
  165. +   }
  166.     cport->rpdev = rpdev;
  167.  
  168.     return 0;
  169. @@ -224,9 +235,9 @@ static void rpmsg_tty_remove(struct rpmsg_device *rpdev)
  170.     rpmsgtty_driver = NULL;
  171.  }
  172.  
  173. -static DEVICE_ATTR(logging_enabled, 0644, show_log_level, toggle_log_level);
  174. +static DRIVER_ATTR(logging_enabled, 0644, show_log_level, toggle_log_level);
  175.  static struct attribute* dev_attrs[] = {
  176. -  &dev_attr_logging_enabled.attr,
  177. +  &driver_attr_logging_enabled.attr,
  178.    NULL,
  179.  };
  180.  static struct attribute_group dev_attr_group = {
  181. diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
  182. index 2a5d6cc..caa0e72 100644
  183. --- a/drivers/rpmsg/virtio_rpmsg_bus.c
  184. +++ b/drivers/rpmsg/virtio_rpmsg_bus.c
  185. @@ -192,17 +192,27 @@ static const struct rpmsg_endpoint_ops virtio_endpoint_ops = {
  186.     .trysend_offchannel = virtio_rpmsg_trysend_offchannel,
  187.  };
  188.  
  189. -static bool logging_enabled = true;
  190. +static bool logging_enabled = false;
  191.  
  192. -static ssize_t show_log_level(struct device* dev, struct device_attribute* attr, char* buf)
  193. +static ssize_t show_log_level(struct device_driver * dev, char* buf)
  194.  {
  195. -        return scnprintf(buf, PAGE_SIZE, "%s\n", logging_enabled ? "0" : "1");
  196. +   return scnprintf(buf, PAGE_SIZE, "%s\n", logging_enabled ? "1 - on" : "0 - off");
  197.  }
  198.  
  199. -static ssize_t toggle_log_level(struct device* dev, struct device_attribute* attr, const char* buf, size_t count)
  200. +static ssize_t toggle_log_level(struct device_driver * dev, const char* buf, size_t count)
  201.  {
  202. -         logging_enabled = logging_enabled ? false : true;
  203. -         return count;
  204. +   if(buf && count > 0)
  205. +   {
  206. +       if(buf[0] == '1')
  207. +       {
  208. +           logging_enabled = true;
  209. +       }
  210. +       else
  211. +       {
  212. +           logging_enabled = false;
  213. +       }
  214. +   }
  215. +    return count;
  216.  }
  217.  
  218.  /**
  219. @@ -576,9 +586,7 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
  220.  
  221.     /* bcasting isn't allowed */
  222.     if (src == RPMSG_ADDR_ANY || dst == RPMSG_ADDR_ANY) {
  223. -                if (logging_enabled) {
  224. -               dev_err(dev, "invalid addr (src 0x%x, dst 0x%x)\n", src, dst);
  225. -                }
  226. +        dev_err(dev, "invalid addr (src 0x%x, dst 0x%x)\n", src, dst);
  227.         return -EINVAL;
  228.     }
  229.  
  230. @@ -592,9 +600,7 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
  231.      * variable-length buffer sizes.
  232.      */
  233.     if (len > RPMSG_BUF_SIZE - sizeof(struct rpmsg_hdr)) {
  234. -                if (logging_enabled) {
  235. -               dev_err(dev, "message is too big (%d)\n", len);
  236. -                }
  237. +        dev_err(dev, "message is too big (%d)\n", len);
  238.         return -EMSGSIZE;
  239.     }
  240.  
  241. @@ -623,9 +629,7 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
  242.  
  243.         /* timeout ? */
  244.         if (!err) {
  245. -                        if (logging_enabled) {
  246. -                   dev_err(dev, "timeout waiting for a tx buffer\n");
  247. -                        }
  248. +           dev_err(dev, "timeout waiting for a tx buffer\n");
  249.             return -ERESTARTSYS;
  250.         }
  251.     }
  252. @@ -637,20 +641,18 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
  253.     msg->reserved = 0;
  254.     memcpy(msg->data, data, len);
  255.  
  256. -        if (logging_enabled) {
  257. -           dev_dbg(dev, "TX From 0x%x, To 0x%x, Len %d, Flags %d, Reserved %d\n",
  258. -               msg->src, msg->dst, msg->len, msg->flags, msg->reserved);
  259. +    if (logging_enabled) {
  260. +        dev_dbg(dev, "TX From 0x%x, To 0x%x, Len %d, Flags %d, Reserved %d\n",
  261. +           msg->src, msg->dst, msg->len, msg->flags, msg->reserved);
  262.  #if defined(CONFIG_DYNAMIC_DEBUG)
  263. -           dynamic_hex_dump("rpmsg_virtio TX: ", DUMP_PREFIX_NONE, 16, 1,
  264. -               msg, sizeof(*msg) + msg->len, true);
  265. +        dynamic_hex_dump("rpmsg_virtio TX: ", DUMP_PREFIX_NONE, 16, 1,
  266. +           msg, sizeof(*msg) + msg->len, true);
  267.  #endif
  268. -        }
  269. +    }
  270.  
  271.     err = sg_init_one_full(&sg, msg, sizeof(*msg) + len);
  272.     if (err) {
  273. -                if (logging_enabled) {
  274. -               dev_err(dev, "virtqueue_add_outbuf sg_init failed: %d\n", err);
  275. -                }
  276. +       dev_err(dev, "virtqueue_add_outbuf sg_init failed: %d\n", err);
  277.         return err;
  278.     }
  279.  
  280. @@ -664,9 +666,7 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
  281.          * (memory won't leak, but rpmsg won't use it again for TX).
  282.          * this will wait for a buffer management overhaul.
  283.          */
  284. -                if (logging_enabled) {
  285. -               dev_err(dev, "virtqueue_add_outbuf failed: %d\n", err);
  286. -                }
  287. +        dev_err(dev, "virtqueue_add_outbuf failed: %d\n", err);
  288.         goto out;
  289.     }
  290.  
  291. @@ -735,14 +735,14 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,
  292.     struct scatterlist sg;
  293.     int err;
  294.  
  295. -        if (logging_enabled) {
  296. -            dev_dbg(dev, "From: 0x%x, To: 0x%x, Len: %d, Flags: %d, Reserved: %d\n",
  297. -                msg->src, msg->dst, msg->len, msg->flags, msg->reserved);
  298. +    if (logging_enabled) {
  299. +         dev_dbg(dev, "From: 0x%x, To: 0x%x, Len: %d, Flags: %d, Reserved: %d\n",
  300. +            msg->src, msg->dst, msg->len, msg->flags, msg->reserved);
  301.  #if defined(CONFIG_DYNAMIC_DEBUG)
  302. -            dynamic_hex_dump("rpmsg_virtio RX: ", DUMP_PREFIX_NONE, 16, 1,
  303. -            msg, sizeof(*msg) + msg->len, true);
  304. +         dynamic_hex_dump("rpmsg_virtio RX: ", DUMP_PREFIX_NONE, 16, 1,
  305. +        msg, sizeof(*msg) + msg->len, true);
  306.  #endif
  307. -        }
  308. +    }
  309.  
  310.     /*
  311.      * We currently use fixed-sized buffers, so trivially sanitize
  312. @@ -750,9 +750,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,
  313.      */
  314.     if (len > RPMSG_BUF_SIZE ||
  315.         msg->len > (len - sizeof(struct rpmsg_hdr))) {
  316. -                if (logging_enabled) {
  317. -               dev_warn(dev, "inbound msg too big: (%d, %d)\n", len, msg->len);
  318. -                }
  319. +        dev_warn(dev, "inbound msg too big: (%d, %d)\n", len, msg->len);
  320.         return -EINVAL;
  321.     }
  322.  
  323. @@ -779,24 +777,21 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,
  324.  
  325.         /* farewell, ept, we don't need you anymore */
  326.         kref_put(&ept->refcount, __ept_release);
  327. -   } else if (logging_enabled)
  328. +   } else if (logging_enabled) {
  329.         dev_warn(dev, "msg received with no recipient\n");
  330. +   }
  331.  
  332.     /* publish the real size of the buffer */
  333.     err = sg_init_one_full(&sg, msg, RPMSG_BUF_SIZE);
  334.     if (err) {
  335. -                if (logging_enabled) {
  336. -               dev_err(dev, "rpmsg_recv_done sg_init failed: %d\n", err);
  337. -                }
  338. +        dev_err(dev, "rpmsg_recv_done sg_init failed: %d\n", err);
  339.         return err;
  340.     }
  341.  
  342.     /* add the buffer back to the remote processor's virtqueue */
  343.     err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, msg, GFP_KERNEL);
  344.     if (err < 0) {
  345. -                if (logging_enabled) {
  346. -               dev_err(dev, "failed to add a virtqueue buffer: %d\n", err);
  347. -                }
  348. +        dev_err(dev, "failed to add a virtqueue buffer: %d\n", err);
  349.         return err;
  350.     }
  351.  
  352. @@ -814,9 +809,7 @@ static void rpmsg_recv_done(struct virtqueue *rvq)
  353.  
  354.     msg = virtqueue_get_buf(rvq, &len);
  355.     if (!msg) {
  356. -                if (logging_enabled) {
  357. -               dev_err(dev, "uhm, incoming signal, but no used buffer ?\n");
  358. -                }
  359. +        dev_err(dev, "uhm, incoming signal, but no used buffer ?\n");
  360.         return;
  361.     }
  362.  
  363. @@ -830,9 +823,9 @@ static void rpmsg_recv_done(struct virtqueue *rvq)
  364.         msg = virtqueue_get_buf(rvq, &len);
  365.     }
  366.  
  367. -        if (logging_enabled) {
  368. -           dev_dbg(dev, "Received %u messages\n", msgs_received);
  369. -        }
  370. +    if (logging_enabled) {
  371. +        dev_dbg(dev, "Received %u messages\n", msgs_received);
  372. +    }
  373.  
  374.     /* tell the remote processor we added another available rx buffer */
  375.     if (msgs_received)
  376. @@ -870,16 +863,14 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,
  377.     int ret;
  378.  
  379.  #if defined(CONFIG_DYNAMIC_DEBUG)
  380. -        if (logging_enabled) {
  381. -           dynamic_hex_dump("NS announcement: ", DUMP_PREFIX_NONE, 16, 1,
  382. -                    data, len, true);
  383. -        }
  384. +    if (logging_enabled) {
  385. +        dynamic_hex_dump("NS announcement: ", DUMP_PREFIX_NONE, 16, 1,
  386. +                data, len, true);
  387. +    }
  388.  #endif
  389.  
  390.     if (len != sizeof(*msg)) {
  391. -                if (logging_enabled) {
  392. -               dev_err(dev, "malformed ns msg (%d)\n", len);
  393. -                }
  394. +        dev_err(dev, "malformed ns msg (%d)\n", len);
  395.         return -EINVAL;
  396.     }
  397.  
  398. @@ -890,20 +881,18 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,
  399.      * in somehow.
  400.      */
  401.     if (rpdev) {
  402. -                if (logging_enabled) {
  403. -               dev_err(dev, "anomaly: ns ept has an rpdev handle\n");
  404. -                }
  405. +        dev_err(dev, "anomaly: ns ept has an rpdev handle\n");
  406.         return -EINVAL;
  407.     }
  408.  
  409.     /* don't trust the remote processor for null terminating the name */
  410.     msg->name[RPMSG_NAME_SIZE - 1] = '\0';
  411.  
  412. -        if (logging_enabled) {
  413. -           dev_info(dev, "%sing channel %s addr 0x%x\n",
  414. -                msg->flags & RPMSG_NS_DESTROY ? "destroy" : "creat",
  415. -                msg->name, msg->addr);
  416. -        }
  417. +    if (logging_enabled) {
  418. +        dev_info(dev, "%sing channel %s addr 0x%x\n",
  419. +            msg->flags & RPMSG_NS_DESTROY ? "destroy" : "creat",
  420. +            msg->name, msg->addr);
  421. +    }
  422.  
  423.     strncpy(chinfo.name, msg->name, sizeof(chinfo.name));
  424.     chinfo.src = RPMSG_ADDR_ANY;
  425. @@ -911,11 +900,11 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,
  426.  
  427.     if (msg->flags & RPMSG_NS_DESTROY) {
  428.         ret = rpmsg_unregister_device(&vrp->vdev->dev, &chinfo);
  429. -       if (ret && logging_enabled)
  430. +       if (ret)
  431.             dev_err(dev, "rpmsg_destroy_channel failed: %d\n", ret);
  432.     } else {
  433.         newch = rpmsg_create_channel(vrp, &chinfo);
  434. -       if (!newch && logging_enabled)
  435. +       if (!newch)
  436.             dev_err(dev, "rpmsg_create_channel failed\n");
  437.     }
  438.  
  439. @@ -973,10 +962,10 @@ static int rpmsg_probe(struct virtio_device *vdev)
  440.         goto vqs_del;
  441.     }
  442.  
  443. -        if (logging_enabled) {
  444. -           dev_dbg(&vdev->dev, "buffers: va %p, dma %pad\n",
  445. -               bufs_va, &vrp->bufs_dma);
  446. -        }
  447. +    if (logging_enabled) {
  448. +        dev_dbg(&vdev->dev, "buffers: va %p, dma %pad\n",
  449. +           bufs_va, &vrp->bufs_dma);
  450. +    }
  451.  
  452.     /* half of the buffers is dedicated for RX */
  453.     vrp->rbufs = bufs_va;
  454. @@ -1034,9 +1023,9 @@ static int rpmsg_probe(struct virtio_device *vdev)
  455.     if (notify)
  456.         virtqueue_notify(vrp->rvq);
  457.  
  458. -        if (logging_enabled) {
  459. -           dev_info(&vdev->dev, "rpmsg host is online\n");
  460. -        }
  461. +    if (logging_enabled) {
  462. +        dev_info(&vdev->dev, "rpmsg host is online\n");
  463. +    }
  464.  
  465.     return 0;
  466.  
  467. @@ -1091,9 +1080,9 @@ static unsigned int features[] = {
  468.     VIRTIO_RPMSG_F_NS,
  469.  };
  470.  
  471. -static DEVICE_ATTR(logging_enabled, 0644, show_log_level, toggle_log_level);
  472. +static DRIVER_ATTR(logging_enabled, 0644, show_log_level, toggle_log_level);
  473.  static struct attribute* dev_attrs[] = {
  474. -  &dev_attr_logging_enabled.attr,
  475. +  &driver_attr_logging_enabled.attr,
  476.    NULL,
  477.  };
  478.  static struct attribute_group dev_attr_group = {
  479. --
  480. 2.7.4
  481.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement