mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Julian Calaby <julian.calaby@gmail.com>
Cc: Christoph Hellwig <hch@infradead.org>,
	Hannes Reinecke <hare@suse.de>,
	"James E.J. Bottomley" <JBottomley@odin.com>,
	"linux-kernel\@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	linux-scsi <linux-scsi@vger.kernel.org>
Subject: Re: RFC: reduce CONFIG_SCSI_CONSTANTS impact by 4k
Date: Tue, 06 Oct 2015 17:39:09 +0200	[thread overview]
Message-ID: <878u7gm2g2.fsf@rasmusvillemoes.dk> (raw)
In-Reply-To: <CAGRGNgXt6qt4K+O9u+Y45rZNh07X=6wh7CdCwJ4mwiYkjXyCWA@mail.gmail.com> (Julian Calaby's message of "Tue, 6 Oct 2015 12:32:47 +1100")

On Tue, Oct 06 2015, Julian Calaby <julian.calaby@gmail.com> wrote:

> Hi Rasmus,
>
>>
>> diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c
>> index 47aaccd5e68e..ccd34b0481cd 100644
>> --- a/drivers/scsi/constants.c
>> +++ b/drivers/scsi/constants.c
>> @@ -292,17 +292,31 @@ bool scsi_opcode_sa_name(int opcode, int service_action,
>>
>>  struct error_info {
>>         unsigned short code12;  /* 0x0302 looks better than 0x03,0x02 */
>> -       const char * text;
>> +       unsigned short size;
>>  };
>>
>>
>> +/*
>> + * There are 700+ entries in this table. To save space, we don't store
>> + * (code, pointer) pairs, which would make sizeof(struct
>> + * error_info)==16 on 64 bits. Rather, the second element just stores
>> + * the size (including \0) of the corresponding string, and we use the
>> + * sum of these to get the appropriate offset into additional_text
>> + * defined below. This approach saves 12 bytes per entry.
>> + */
>>  static const struct error_info additional[] =
>>  {
>> -#define SENSE_CODE(c, s) {c, s},
>> +#define SENSE_CODE(c, s) {c, sizeof(s)},
>>  #include "sense_codes.h"
>>  #undef SENSE_CODE
>>  };
>>
>> +static const char *additional_text =
>> +#define SENSE_CODE(c, s) s "\0"
>> +#include "sense_codes.h"
>> +#undef SENSE_CODE
>> +       ;
>> +
>>  struct error_info2 {
>>         unsigned char code1, code2_min, code2_max;
>>         const char * str;
>> @@ -364,11 +378,14 @@ scsi_extd_sense_format(unsigned char asc, unsigned char ascq, const char **fmt)
>>  {
>>         int i;
>>         unsigned short code = ((asc << 8) | ascq);
>> +       unsigned offset = 0;
>>
>>         *fmt = NULL;
>> -       for (i = 0; additional[i].text; i++)
>> +       for (i = 0; i < ARRAY_SIZE(additional); i++) {
>>                 if (additional[i].code12 == code)
>> -                       return additional[i].text;
>> +                       return additional_text + offset;
>> +               offset += additional[i].size;
>
> You don't seem to be accounting for the null bytes here.

Well, no, I account for the nul bytes where I define the table (the
comment actually says as much). sizeof("foo") is 4. Since
additional_text ends up pointing to a string containing

"foo" "\0" "xyzzy" "\0" "..." "\0"

aka

"foo\0xyzzy\0...\0"

this is the right amount to skip. As I said in the cover letter, I did
test this (so that I'd at least catch silly off-by-ones), and I do get
the right strings out.

Thanks,
Rasmus

  reply	other threads:[~2015-10-06 15:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-30 17:30 Rasmus Villemoes
2015-10-03 17:14 ` Christoph Hellwig
2015-10-03 22:09   ` Rasmus Villemoes
2015-10-04  8:02     ` Christoph Hellwig
2015-10-05  9:26       ` [PATCH 0/2] scsi: reduce CONFIG_SCSI_CONSTANTS=y impact by 8k Rasmus Villemoes
2015-10-05  9:26         ` [PATCH 1/2] scsi: move Additional Sense Codes to separate file Rasmus Villemoes
2015-10-05 14:05           ` Bart Van Assche
2015-10-06 15:27             ` Rasmus Villemoes
2015-10-17 22:12               ` Rasmus Villemoes
2015-10-05  9:26         ` [PATCH 2/2] scsi: reduce CONFIG_SCSI_CONSTANTS=y impact by 8k Rasmus Villemoes
2015-10-05 14:11           ` Bart Van Assche
2015-10-06 15:31             ` Rasmus Villemoes
2015-10-06  1:32     ` RFC: reduce CONFIG_SCSI_CONSTANTS impact by 4k Julian Calaby
2015-10-06 15:39       ` Rasmus Villemoes [this message]
2015-10-06 23:01         ` Julian Calaby

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=878u7gm2g2.fsf@rasmusvillemoes.dk \
    --to=linux@rasmusvillemoes.dk \
    --cc=JBottomley@odin.com \
    --cc=hare@suse.de \
    --cc=hch@infradead.org \
    --cc=julian.calaby@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.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

Powered by JetHome