linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][RESEND] block: sed-opal: fix response string extraction
@ 2018-03-01 13:26 Jonas Rabenstein
  2018-03-07  0:23 ` Derrick, Jonathan
  0 siblings, 1 reply; 3+ messages in thread
From: Jonas Rabenstein @ 2018-03-01 13:26 UTC (permalink / raw)
  To: Jonas Rabenstein, Scott Bauer, Jonathan Derrick, Jens Axboe
  Cc: linux-block, linux-kernel

Tokens are prefixed by a variable length of bytes. If a bytestring is
not stored in an tiny or short atom, we have to skip more than one byte
in order to have the actual bytes not prefixed by the bytes describing
the actual length of the string.

Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
---
 block/sed-opal.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/block/sed-opal.c b/block/sed-opal.c
index 525506bed399..33052d0111de 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -876,6 +876,9 @@ static int response_parse(const u8 *buf, size_t length,
 static size_t response_get_string(const struct parsed_resp *resp, int n,
 				  const char **store)
 {
+	u8 skip;
+	const struct opal_resp_tok *token;
+
 	*store = NULL;
 	if (!resp) {
 		pr_debug("Response is NULL\n");
@@ -888,13 +891,30 @@ static size_t response_get_string(const struct parsed_resp *resp, int n,
 		return 0;
 	}
 
-	if (resp->toks[n].type != OPAL_DTA_TOKENID_BYTESTRING) {
+	token = &resp->toks[n];
+	if (token->type != OPAL_DTA_TOKENID_BYTESTRING) {
 		pr_debug("Token is not a byte string!\n");
 		return 0;
 	}
 
-	*store = resp->toks[n].pos + 1;
-	return resp->toks[n].len - 1;
+	switch (token->width) {
+	case OPAL_WIDTH_TINY:
+	case OPAL_WIDTH_SHORT:
+		skip = 1;
+		break;
+	case OPAL_WIDTH_MEDIUM:
+		skip = 2;
+		break;
+	case OPAL_WIDTH_LONG:
+		skip = 4;
+		break;
+	default:
+		pr_debug("Token has invalid width!\n");
+		return 0;
+	}
+
+	*store = token->pos + skip;
+	return token->len - skip;
 }
 
 static u64 response_get_u64(const struct parsed_resp *resp, int n)
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH][RESEND] block: sed-opal: fix response string extraction
  2018-03-01 13:26 [PATCH][RESEND] block: sed-opal: fix response string extraction Jonas Rabenstein
@ 2018-03-07  0:23 ` Derrick, Jonathan
  2018-03-07 22:45   ` Scott Bauer
  0 siblings, 1 reply; 3+ messages in thread
From: Derrick, Jonathan @ 2018-03-07  0:23 UTC (permalink / raw)
  To: Bauer, Scott, jonas.rabenstein, axboe; +Cc: linux-kernel, linux-block

[-- Attachment #1: Type: text/plain, Size: 2017 bytes --]

This looks correct.

Adding my Ack unless Scott has objections

Acked-by: Jonathan Derrick <jonathan.derrick@intel.com>

On Thu, 2018-03-01 at 14:26 +0100, Jonas Rabenstein wrote:
> Tokens are prefixed by a variable length of bytes. If a bytestring is
> not stored in an tiny or short atom, we have to skip more than one
> byte
> in order to have the actual bytes not prefixed by the bytes
> describing
> the actual length of the string.
> 
> Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlange
> n.de>
> ---
>  block/sed-opal.c | 26 +++++++++++++++++++++++---
>  1 file changed, 23 insertions(+), 3 deletions(-)
> 
> diff --git a/block/sed-opal.c b/block/sed-opal.c
> index 525506bed399..33052d0111de 100644
> --- a/block/sed-opal.c
> +++ b/block/sed-opal.c
> @@ -876,6 +876,9 @@ static int response_parse(const u8 *buf, size_t
> length,
>  static size_t response_get_string(const struct parsed_resp *resp,
> int n,
>  				  const char **store)
>  {
> +	u8 skip;
> +	const struct opal_resp_tok *token;
> +
>  	*store = NULL;
>  	if (!resp) {
>  		pr_debug("Response is NULL\n");
> @@ -888,13 +891,30 @@ static size_t response_get_string(const struct
> parsed_resp *resp, int n,
>  		return 0;
>  	}
>  
> -	if (resp->toks[n].type != OPAL_DTA_TOKENID_BYTESTRING) {
> +	token = &resp->toks[n];
> +	if (token->type != OPAL_DTA_TOKENID_BYTESTRING) {
>  		pr_debug("Token is not a byte string!\n");
>  		return 0;
>  	}
>  
> -	*store = resp->toks[n].pos + 1;
> -	return resp->toks[n].len - 1;
> +	switch (token->width) {
> +	case OPAL_WIDTH_TINY:
> +	case OPAL_WIDTH_SHORT:
> +		skip = 1;
> +		break;
> +	case OPAL_WIDTH_MEDIUM:
> +		skip = 2;
> +		break;
> +	case OPAL_WIDTH_LONG:
> +		skip = 4;
> +		break;
> +	default:
> +		pr_debug("Token has invalid width!\n");
> +		return 0;
> +	}
> +
> +	*store = token->pos + skip;
> +	return token->len - skip;
>  }
>  
>  static u64 response_get_u64(const struct parsed_resp *resp, int n)

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 3278 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH][RESEND] block: sed-opal: fix response string extraction
  2018-03-07  0:23 ` Derrick, Jonathan
@ 2018-03-07 22:45   ` Scott Bauer
  0 siblings, 0 replies; 3+ messages in thread
From: Scott Bauer @ 2018-03-07 22:45 UTC (permalink / raw)
  To: Derrick, Jonathan; +Cc: jonas.rabenstein, axboe, linux-kernel, linux-block

On Tue, Mar 06, 2018 at 04:23:24PM -0800, Derrick, Jonathan wrote:
> This looks correct.
> 
> Adding my Ack unless Scott has objections
> 
> Acked-by: Jonathan Derrick <jonathan.derrick@intel.com>


Reviewed-by: Scott Bauer <scott.bauer@intel.com>

Nice catch Jonas! Sorry you had to resend, my message filtering was a little
too agressive and this slipped through the cracks, that has been remediated.


> 
> On Thu, 2018-03-01 at 14:26 +0100, Jonas Rabenstein wrote:
> > Tokens are prefixed by a variable length of bytes. If a bytestring is
> > not stored in an tiny or short atom, we have to skip more than one
> > byte
> > in order to have the actual bytes not prefixed by the bytes
> > describing
> > the actual length of the string.
> > 
> > Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlange
> > n.de>
> > ---
> >  block/sed-opal.c | 26 +++++++++++++++++++++++---
> >  1 file changed, 23 insertions(+), 3 deletions(-)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-03-07 23:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-01 13:26 [PATCH][RESEND] block: sed-opal: fix response string extraction Jonas Rabenstein
2018-03-07  0:23 ` Derrick, Jonathan
2018-03-07 22:45   ` Scott Bauer

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).