linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Xiang Xiao <xiaoxiang781216@gmail.com>
Cc: rdunlap@infradead.org, gregkh@linuxfoundation.org,
	alexander.shishkin@linux.intel.com, ohad@wizery.com,
	bjorn.andersson@linaro.org, wendy.liang@xilinx.com,
	arnaud.pouliquen@st.com, kumar.gala@linaro.org,
	linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org,
	Guiding Li <liguiding@pinecone.net>
Subject: Re: [PATCH V2 2/2] rpmsg: add syslog redirection driver
Date: Thu, 14 Feb 2019 15:09:40 +0200	[thread overview]
Message-ID: <20190214130940.GV9224@smile.fi.intel.com> (raw)
In-Reply-To: <1550124158-1111-2-git-send-email-xiaoxiang@xiaomi.com>

On Thu, Feb 14, 2019 at 02:02:38PM +0800, Xiang Xiao wrote:
> From: Guiding Li <liguiding@pinecone.net>
> 
> This driver allows the remote processor to redirect the output of
> syslog or printf into the kernel log, which is very useful to see
> what happen in the remote side.

> +struct rpmsg_syslog_header {
> +	u32				command;
> +	s32				result;
> +} __packed;

Isn't packed already?

> +struct rpmsg_syslog_transfer {
> +	struct rpmsg_syslog_header	header;
> +	u32				count;
> +	char				data[0];
> +} __packed;

Ditto.

> +static int rpmsg_syslog_callback(struct rpmsg_device *rpdev,
> +				 void *data, int len, void *priv_, u32 src)
> +{
> +	struct rpmsg_syslog *priv = dev_get_drvdata(&rpdev->dev);
> +	struct rpmsg_syslog_transfer *msg = data;
> +	struct rpmsg_syslog_transfer_done done;
> +	unsigned int copied = msg->count;
> +	unsigned int printed = 0;
> +	const char *nl;
> +
> +	if (msg->header.command != RPMSG_SYSLOG_TRANSFER)
> +		return -EINVAL;
> +
> +	/* output the message before '\n' to the kernel log */
> +	nl = memrchr(msg->data, '\n', msg->count);

Hmm... To me it sounds somehow fragile.

If your text contains binary data, how can you guarantee that it would be not
in the middle of two \n:s? OTOH, if it text data, why do you need to take all
strings at once? It might be worse from performance prospective (if you know
how and when printk() supplies buffer to the console).

> +	if (nl) {
> +		printed = nl + 1 - msg->data;
> +		copied = msg->count - printed;
> +
> +		if (priv->next) {
> +			pr_info("%.*s%.*s", priv->next,
> +				priv->buf, printed, msg->data);
> +			priv->next = 0;
> +		} else {
> +			pr_info("%.*s", printed, msg->data);
> +		}
> +	}
> +
> +	/* append the message after '\n' to the buffer */

> +	if (copied != 0) {



> +		unsigned int newsize = priv->next + copied;
> +
> +		if (newsize > priv->size) {
> +			char *newbuf;
> +
> +			newbuf = krealloc(priv->buf, newsize, GFP_KERNEL);
> +			if (newbuf) {
> +				priv->buf  = newbuf;
> +				priv->size = newsize;
> +			} else {
> +				copied = priv->size - priv->next;
> +			}
> +		}
> +

> +		strncpy(priv->buf + priv->next, msg->data + printed, copied);

Hmm... shouldn't be memcpy()?

> +		priv->next += copied;
> +	}
> +
> +	done.command = RPMSG_SYSLOG_TRANSFER_DONE;
> +	done.result  = printed + copied;
> +	return rpmsg_send(rpdev->ept, &done, sizeof(done));
> +}
> +
> +static int rpmsg_syslog_probe(struct rpmsg_device *rpdev)
> +{
> +	struct rpmsg_syslog *priv;
> +
> +	priv = devm_kzalloc(&rpdev->dev, sizeof(*priv), GFP_KERNEL);
> +	if (!priv)
> +		return -ENOMEM;
> +
> +	dev_set_drvdata(&rpdev->dev, priv);
> +	return 0;
> +}
> +
> +static void rpmsg_syslog_remove(struct rpmsg_device *rpdev)
> +{
> +	struct rpmsg_syslog *priv = dev_get_drvdata(&rpdev->dev);
> +

> +	/* flush the buffered log if need */
> +	if (priv->next)
> +		pr_info("%.*s\n", priv->next, priv->buf);
> +	kfree(priv->buf);

I don't see how it's serialized. Does rpmsg core take care of this?

> +}

> +#ifdef CONFIG_PM_SLEEP

You can consider to use __maybe_unused annotation to the below function.

> +static int rpmsg_syslog_dev_suspend(struct device *dev)
> +{

> +}
> +
> +static int rpmsg_syslog_dev_resume(struct device *dev)
> +{

> +}
> +#endif

> +static const struct rpmsg_device_id rpmsg_syslog_id_table[] = {
> +	{ .name = "rpmsg-syslog" },
> +	{ },

Terminator better without comma.

> +};

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2019-02-14 13:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-14  6:02 [PATCH V2 1/2] lib/string: add memrchr function Xiang Xiao
2019-02-14  6:02 ` [PATCH V2 2/2] rpmsg: add syslog redirection driver Xiang Xiao
2019-02-14 13:09   ` Andy Shevchenko [this message]
2019-02-14 13:11     ` Andy Shevchenko
2019-02-14 16:31     ` xiang xiao
2019-02-15 15:06       ` Andy Shevchenko
2019-02-16 16:52         ` xiang xiao
2019-02-14 12:53 ` [PATCH V2 1/2] lib/string: add memrchr function Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190214130940.GV9224@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=arnaud.pouliquen@st.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kumar.gala@linaro.org \
    --cc=liguiding@pinecone.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=ohad@wizery.com \
    --cc=rdunlap@infradead.org \
    --cc=wendy.liang@xilinx.com \
    --cc=xiaoxiang781216@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).