mfd: cros_ec: check for NULL transfer function
Subsystems (2)
PATCH 1/1 mfd: cros_ec: check for NULL transfer function
From: Enrico Granata <[email protected]>
As new transfer mechanisms are added to the EC codebase, they may not support v2 of the EC protocol.
If the v3 initial handshake transfer fails, the kernel will try and call cmd_xfer as a fallback. If v2 is not supported, cmd_xfer will be NULL, and the code will end up causing a kernel panic.
Add a check for NULL before calling the transfer function, along with a helpful comment explaining how one might end up in this situation.
--- drivers/platform/chrome/cros_ec_proto.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/platform/chrome/cros_ec_proto.c +10 -0
@@ -56,6 +56,16 @@ static int send_command(struct cros_ec_device *ec_dev,else xfer_fxn = ec_dev->cmd_xfer; +if (xfer_fxn ==NULL ) { +/* This error can happen if a communication error happened and +* the EC is trying to use protocol v2, on an underlying +* communication mechanism that does not support v2. +*/ +dev_err (ec_dev->dev, +"missing EC transfer API, cannot send command\n" ); +return -EIO ; + } + ret = (*xfer_fxn)(ec_dev, msg);if (msg->result ==EC_RES_IN_PROGRESS ) {int i;
Signature · 1 line
2.21.0.392.gf8f6787159e-goog
Quoted 24 lines · On Wed, Apr 3, 2019 at 11:31 AM <[email protected]> wrote:
From: Enrico Granata <[email protected]>
As new transfer mechanisms are added to the EC codebase, they may not support v2 of the EC protocol.
If the v3 initial handshake transfer fails, the kernel will try and call
cmd_xferas a fallback. If v2 is not supported,cmd_xferwill be NULL, and the code will end up causing a kernel panic.Add a check for NULL before calling the transfer function, along with a helpful comment explaining how one might end up in this situation.
Signed-off-by Enrico Granata <[email protected]>--- drivers/platform/chrome/cros_ec_proto.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/platform/chrome/cros_ec_proto.c +0
-0
drivers/platform/chrome/cros_ec_proto.c static int send_command(struct cros_ec_device *ec_dev, · line 63
Quoted 8 lines
drivers/platform/chrome/cros_ec_proto.c +5
-0@@ -56,6 +56,16 @@ static int send_command(struct cros_ec_device *ec_dev,else xfer_fxn = ec_dev->cmd_xfer; +if (xfer_fxn ==NULL ) { +/* This error can happen if a communication error happened and +* the EC is trying to use protocol v2, on an underlying +* communication mechanism that does not support v2. +*/
I am not personally a friend of networking-style multi-line comments.
drivers/platform/chrome/cros_ec_proto.c static int send_command(struct cros_ec_device *ec_dev, · line 65
Quoted 2 lines
drivers/platform/chrome/cros_ec_proto.c +2
-0+dev_err (ec_dev->dev, +"missing EC transfer API, cannot send command\n" );
That message will be displayed each time a message is sent, ie in practice for each message. Is there any value in that, other than clogging the log ?
Guenter
Quoted 9 lines
drivers/platform/chrome/cros_ec_proto.c +3
-1+return -EIO ; + } + ret = (*xfer_fxn)(ec_dev, msg);if (msg->result ==EC_RES_IN_PROGRESS ) {int i; --2.21.0.392.gf8f6787159e-goog
I can certainly add a "did_print_error" flag or some such, but in practice, if the transfer function is NULL, the initial handshake will fail, and this will in turn cause EC registration to fail, and no further communication should occur, so no further log entries will be printed.
Thanks
Enrico Granata | [email protected] | ChromeOS | MTV1600
Quoted 55 lines · Guenter Roeck
Quoted 24 lines · On Wed, Apr 3, 2019 at 11:31 AM <[email protected]> wrote:
From: Enrico Granata <[email protected]>
As new transfer mechanisms are added to the EC codebase, they may not support v2 of the EC protocol.
If the v3 initial handshake transfer fails, the kernel will try and call
cmd_xferas a fallback. If v2 is not supported,cmd_xferwill be NULL, and the code will end up causing a kernel panic.Add a check for NULL before calling the transfer function, along with a helpful comment explaining how one might end up in this situation.
Signed-off-by Enrico Granata <[email protected]>--- drivers/platform/chrome/cros_ec_proto.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/platform/chrome/cros_ec_proto.c +0
-0drivers/platform/chrome/cros_ec_proto.c static int send_command(struct cros_ec_device *ec_dev, · line 63
Quoted 8 lines
drivers/platform/chrome/cros_ec_proto.c +5
-0@@ -56,6 +56,16 @@ static int send_command(struct cros_ec_device *ec_dev,else xfer_fxn = ec_dev->cmd_xfer; +if (xfer_fxn ==NULL ) { +/* This error can happen if a communication error happened and +* the EC is trying to use protocol v2, on an underlying +* communication mechanism that does not support v2. +*/ I am not personally a friend of networking-style multi-line comments.
drivers/platform/chrome/cros_ec_proto.c static int send_command(struct cros_ec_device *ec_dev, · line 65
Quoted 2 lines
drivers/platform/chrome/cros_ec_proto.c +2
-0+dev_err (ec_dev->dev, +"missing EC transfer API, cannot send command\n" );That message will be displayed each time a message is sent, ie in practice for each message. Is there any value in that, other than clogging the log ?
Guenter
Quoted 9 lines
drivers/platform/chrome/cros_ec_proto.c +3
-1+return -EIO ; + } + ret = (*xfer_fxn)(ec_dev, msg);if (msg->result ==EC_RES_IN_PROGRESS ) {int i; --2.21.0.392.gf8f6787159e-goog
A message that is not in the archive (sent off-list or not yet received): CAPR809vTZSFtNp61WQsOFRkFacO_8XEdicqFq9uYMkUMdjEsqg@mail.gmail.com
Quoted 3 lines · Enrico Granata
I can certainly add a "
did_print_error" flag or some such, but in practice, if the transfer function is NULL, the initial handshake will fail, and this will in turn cause EC registration to fail, and no further communication should occur, so no further log entries will be printed.
Sorry, I am a bit lost. Why would dev_err_once() not work ?
Guenter
Quoted 61 lines
Thanks
Enrico Granata | [email protected] | ChromeOS | MTV1600
Quoted 55 lines · Guenter Roeck
Quoted 24 lines · On Wed, Apr 3, 2019 at 11:31 AM <[email protected]> wrote:
From: Enrico Granata <[email protected]>
As new transfer mechanisms are added to the EC codebase, they may not support v2 of the EC protocol.
If the v3 initial handshake transfer fails, the kernel will try and call
cmd_xferas a fallback. If v2 is not supported,cmd_xferwill be NULL, and the code will end up causing a kernel panic.Add a check for NULL before calling the transfer function, along with a helpful comment explaining how one might end up in this situation.
Signed-off-by Enrico Granata <[email protected]>--- drivers/platform/chrome/cros_ec_proto.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/platform/chrome/cros_ec_proto.c +0
-0drivers/platform/chrome/cros_ec_proto.c static int send_command(struct cros_ec_device *ec_dev, · line 63
Quoted 8 lines
drivers/platform/chrome/cros_ec_proto.c +5
-0@@ -56,6 +56,16 @@ static int send_command(struct cros_ec_device *ec_dev,else xfer_fxn = ec_dev->cmd_xfer; +if (xfer_fxn ==NULL ) { +/* This error can happen if a communication error happened and +* the EC is trying to use protocol v2, on an underlying +* communication mechanism that does not support v2. +*/ I am not personally a friend of networking-style multi-line comments.
drivers/platform/chrome/cros_ec_proto.c static int send_command(struct cros_ec_device *ec_dev, · line 65
Quoted 2 lines
drivers/platform/chrome/cros_ec_proto.c +2
-0+dev_err (ec_dev->dev, +"missing EC transfer API, cannot send command\n" );That message will be displayed each time a message is sent, ie in practice for each message. Is there any value in that, other than clogging the log ?
Guenter
Quoted 9 lines
drivers/platform/chrome/cros_ec_proto.c +3
-1+return -EIO ; + } + ret = (*xfer_fxn)(ec_dev, msg);if (msg->result ==EC_RES_IN_PROGRESS ) {int i; --2.21.0.392.gf8f6787159e-goog
Because I did not know about it till right now. Thanks for the suggestion. Will upload a v2 as soon as I get a chance.
Quoted 70 lines · Guenter Roeck
Quoted 3 lines · Enrico Granata
I can certainly add a "
did_print_error" flag or some such, but in practice, if the transfer function is NULL, the initial handshake will fail, and this will in turn cause EC registration to fail, and no further communication should occur, so no further log entries will be printed.Sorry, I am a bit lost. Why would
dev_err_once()not work ?Guenter
Quoted 61 lines
Thanks
Enrico Granata | [email protected] | ChromeOS | MTV1600
Quoted 55 lines · Guenter Roeck
Quoted 24 lines · On Wed, Apr 3, 2019 at 11:31 AM <[email protected]> wrote:
From: Enrico Granata <[email protected]>
As new transfer mechanisms are added to the EC codebase, they may not support v2 of the EC protocol.
If the v3 initial handshake transfer fails, the kernel will try and call
cmd_xferas a fallback. If v2 is not supported,cmd_xferwill be NULL, and the code will end up causing a kernel panic.Add a check for NULL before calling the transfer function, along with a helpful comment explaining how one might end up in this situation.
Signed-off-by Enrico Granata <[email protected]>--- drivers/platform/chrome/cros_ec_proto.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/platform/chrome/cros_ec_proto.c +0
-0drivers/platform/chrome/cros_ec_proto.c static int send_command(struct cros_ec_device *ec_dev, · line 63
Quoted 8 lines
drivers/platform/chrome/cros_ec_proto.c +5
-0@@ -56,6 +56,16 @@ static int send_command(struct cros_ec_device *ec_dev,else xfer_fxn = ec_dev->cmd_xfer; +if (xfer_fxn ==NULL ) { +/* This error can happen if a communication error happened and +* the EC is trying to use protocol v2, on an underlying +* communication mechanism that does not support v2. +*/ I am not personally a friend of networking-style multi-line comments.
drivers/platform/chrome/cros_ec_proto.c static int send_command(struct cros_ec_device *ec_dev, · line 65
Quoted 2 lines
drivers/platform/chrome/cros_ec_proto.c +2
-0+dev_err (ec_dev->dev, +"missing EC transfer API, cannot send command\n" );That message will be displayed each time a message is sent, ie in practice for each message. Is there any value in that, other than clogging the log ?
Guenter
Quoted 9 lines
drivers/platform/chrome/cros_ec_proto.c +3
-1+return -EIO ; + } + ret = (*xfer_fxn)(ec_dev, msg);if (msg->result ==EC_RES_IN_PROGRESS ) {int i; --2.21.0.392.gf8f6787159e-goog
PATCH v2 1/1 mfd: cros_ec: check for NULL transfer function
In reply to Guenter RoeckFrom: Enrico Granata <[email protected]>
As new transfer mechanisms are added to the EC codebase, they may not support v2 of the EC protocol.
If the v3 initial handshake transfer fails, the kernel will try and call cmd_xfer as a fallback. If v2 is not supported, cmd_xfer will be NULL, and the code will end up causing a kernel panic.
Add a check for NULL before calling the transfer function, along with a helpful comment explaining how one might end up in this situation.
--- drivers/platform/chrome/cros_ec_proto.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/platform/chrome/cros_ec_proto.c +10 -0
@@ -56,6 +56,16 @@ static int send_command(struct cros_ec_device *ec_dev,else xfer_fxn = ec_dev->cmd_xfer; +if (xfer_fxn ==NULL ) { +/* This error can happen if a communication error happened and +* the EC is trying to use protocol v2, on an underlying +* communication mechanism that does not support v2. +*/ +dev_err_once (ec_dev->dev, +"missing EC transfer API, cannot send command\n" ); +return -EIO ; + } + ret = (*xfer_fxn)(ec_dev, msg);if (msg->result ==EC_RES_IN_PROGRESS ) {int i;
Signature · 1 line
2.21.0.392.gf8f6787159e-goog
Quoted 43 lines · On Wed, Apr 3, 2019 at 4:40 PM <[email protected]> wrote:
From: Enrico Granata <[email protected]>
As new transfer mechanisms are added to the EC codebase, they may not support v2 of the EC protocol.
If the v3 initial handshake transfer fails, the kernel will try and call
cmd_xferas a fallback. If v2 is not supported,cmd_xferwill be NULL, and the code will end up causing a kernel panic.Add a check for NULL before calling the transfer function, along with a helpful comment explaining how one might end up in this situation.
Signed-off-by Enrico Granata <[email protected]>--- drivers/platform/chrome/cros_ec_proto.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/platform/chrome/cros_ec_proto.c +10
-1@@ -56,6 +56,16 @@ static int send_command(struct cros_ec_device *ec_dev,else xfer_fxn = ec_dev->cmd_xfer; +if (xfer_fxn ==NULL ) { +/* This error can happen if a communication error happened and +* the EC is trying to use protocol v2, on an underlying +* communication mechanism that does not support v2. +*/ +dev_err_once (ec_dev->dev, +"missing EC transfer API, cannot send command\n" ); +return -EIO ; + } + ret = (*xfer_fxn)(ec_dev, msg);if (msg->result ==EC_RES_IN_PROGRESS ) {int i; --2.21.0.392.gf8f6787159e-goog
Hi Enrico,
Many thanks to send this upstream.
Quoted 30 lines · Jett ✈ Rink
Reviewed-by Jett Rink <[email protected]>Quoted 27 lines · On Wed, Apr 3, 2019 at 4:40 PM <[email protected]> wrote:
From: Enrico Granata <[email protected]>
As new transfer mechanisms are added to the EC codebase, they may not support v2 of the EC protocol.
If the v3 initial handshake transfer fails, the kernel will try and call
cmd_xferas a fallback. If v2 is not supported,cmd_xferwill be NULL, and the code will end up causing a kernel panic.Add a check for NULL before calling the transfer function, along with a helpful comment explaining how one might end up in this situation.
Signed-off-by Enrico Granata <[email protected]>--- drivers/platform/chrome/cros_ec_proto.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/platform/chrome/cros_ec_proto.c +0
-0@@ -56,6 +56,16 @@ static int send_command(struct cros_ec_device *ec_dev,else xfer_fxn = ec_dev->cmd_xfer;
Quoted 2 lines
drivers/platform/chrome/cros_ec_proto.c static int send_command(struct cros_ec_device *ec_dev, · line 60
Quoted 2 lines
drivers/platform/chrome/cros_ec_proto.c +2
-0+if (xfer_fxn ==NULL ) { +/* This error can happen if a communication error happened and
Like Guenter I personally don't like the networking-style multi-line comments. We try to use the default kernel-style so if you don't mind I'll change this.
Quoted 6 lines
Quoted 6 lines
drivers/platform/chrome/cros_ec_proto.c +6
-0+* the EC is trying to use protocol v2, on an underlying +* communication mechanism that does not support v2. +*/ +dev_err_once (ec_dev->dev, +"missing EC transfer API, cannot send command\n" ); +return -EIO ;
Quoted 8 lines
Quoted 8 lines
drivers/platform/chrome/cros_ec_proto.c +2
-1+ } + ret = (*xfer_fxn)(ec_dev, msg);if (msg->result ==EC_RES_IN_PROGRESS ) {int i; --2.21.0.392.gf8f6787159e-goog
I'll add the patch to the for-next branch in chrome-platform repository for auto-builders to play with. If all goes well I'll queue the patch for chrome-platform-5.2.
Thanks,
Enric