From: carlo@caione.org (Carlo Caione)
To: linus-amlogic@lists.infradead.org
Subject: [PATCH 2/2] firmware: meson-sm: Allow 0 as valid return value
Date: Fri, 3 Mar 2017 16:17:59 +0100 [thread overview]
Message-ID: <20170303151759.8330-3-carlo@caione.org> (raw)
In-Reply-To: <20170303151759.8330-1-carlo@caione.org>
From: Carlo Caione <carlo@endlessm.com>
Some special SMC calls (i.e. the function used to retrieve the serial
number of the Amlogic SoCs) returns 0 in the register 0 also when the
data was successfully read instead of using the register to hold the
number of bytes returned in the bounce buffer as expected.
With the current implementation of the driver this is seen as an error
and meson_sm_call_read() returns an error even though the data was
correctly read.
To deal with this when we have no information about the amount of read
data (that is 0 is returned by the SMC call) we return to the caller
the requested amount of data and 0 as return value.
Signed-off-by: Carlo Caione <carlo@endlessm.com>
---
drivers/firmware/meson/meson_sm.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/firmware/meson/meson_sm.c b/drivers/firmware/meson/meson_sm.c
index 5f30a5774e57..ff204421117b 100644
--- a/drivers/firmware/meson/meson_sm.c
+++ b/drivers/firmware/meson/meson_sm.c
@@ -136,11 +136,14 @@ EXPORT_SYMBOL(meson_sm_call);
* @arg4: SMC32 Argument 4
*
* Return: size of read data on success, a negative value on error
+ * When 0 is returned there is no guarantee about the amount of
+ * data read and bsize bytes are copied in buffer.
*/
int meson_sm_call_read(void *buffer, unsigned int bsize, unsigned int cmd_index,
u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4)
{
u32 size;
+ int ret;
if (!fw.chip)
return -ENOENT;
@@ -154,13 +157,18 @@ int meson_sm_call_read(void *buffer, unsigned int bsize, unsigned int cmd_index,
if (meson_sm_call(cmd_index, &size, arg0, arg1, arg2, arg3, arg4) < 0)
return -EINVAL;
- if (!size || size > bsize)
+ if (size > bsize)
return -EINVAL;
+ ret = size;
+
+ if (!size)
+ size = bsize;
+
if (buffer)
memcpy(buffer, fw.sm_shmem_out_base, size);
- return size;
+ return ret;
}
EXPORT_SYMBOL(meson_sm_call_read);
--
2.12.0
next prev parent reply other threads:[~2017-03-03 15:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-03 15:17 [PATCH 0/2] meson-sm: Fix issues when reading data from sm Carlo Caione
2017-03-03 15:17 ` [PATCH 1/2] firmware: meson-sm: Check for buffer output size Carlo Caione
2017-03-22 16:28 ` Srinivas Kandagatla
2017-03-03 15:17 ` Carlo Caione [this message]
2017-03-22 15:55 ` [PATCH 0/2] meson-sm: Fix issues when reading data from sm Kevin Hilman
2017-03-23 10:31 ` Mark Rutland
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=20170303151759.8330-3-carlo@caione.org \
--to=carlo@caione.org \
--cc=linus-amlogic@lists.infradead.org \
/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
all inboxes | Powered by JetHome®