All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: Bart Van Assche <Bart.VanAssche@wdc.com>,
	"martin.petersen@oracle.com" <martin.petersen@oracle.com>
Cc: "hch@lst.de" <hch@lst.de>,
	"james.bottomley@hansenpartnership.com"
	<james.bottomley@hansenpartnership.com>,
	"Alan@suse.de" <Alan@suse.de>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"hare@suse.com" <hare@suse.com>,
	"stern@rowland.harvard.edu" <stern@rowland.harvard.edu>
Subject: Re: [PATCHv4 2/5] scsi: Export blacklist flags to sysfs
Date: Wed, 30 Aug 2017 12:50:57 +0200	[thread overview]
Message-ID: <9e7eb07d-7796-ace6-ee04-d88e22e730b0@suse.de> (raw)
In-Reply-To: <1504022564.2653.12.camel@wdc.com>

On 08/29/2017 06:02 PM, Bart Van Assche wrote:
> On Tue, 2017-08-29 at 10:49 +0200, Hannes Reinecke wrote:
>> [ ... ]
>> +$(obj)/scsi_sysfs.o: $(obj)/scsi_devinfo_tbl.c
>> +
>> +quiet_cmd_bflags = GEN     $@
>> +	cmd_bflags = $(PERL) -s $(src)/mktbl.pl BLIST $< > $@
> 
> Hello Hannes,
> 
> Is it considered acceptable to require that perl is available to build the
> kernel? People who build the kernel for embedded systems probably won't be
> happy if this is a new requirement. See e.g. "PATCH [0/3]: Simplify the
> kernel build by removing perl" (https://lkml.org/lkml/2009/1/2/20).
> 
> Have you noticed that for other generated files a _shipped version is
> provided?
> 
Ah. Good point. Will be doing so.

>> +
>> +$(obj)/scsi_devinfo_tbl.c: include/scsi/scsi_devinfo.h
>> +	$(call if_changed,bflags)
>> +
>>  # If you want to play with the firmware, uncomment
>>  # GENERATE_FIRMWARE := 1
>>  
>> diff --git a/drivers/scsi/mktbl.pl b/drivers/scsi/mktbl.pl
>> [ ... ]
>> +my $prf;
>> +
>> +$prf = $ARGV[0];
>> +open IN_FILE, "<$ARGV[1]" || die;
>> +print "\t/*\n\t * Automatically generated by ", $0, ".\n";
>> +print "\t * Do not edit.\n\t */\n";
>> +while (<IN_FILE>) {
>> +    chomp;
>> +    if (/^#define ${prf}_([^[:blank:]]*).*/) {
>> +	print "\t{ ", $prf, "_", $1, ", \"", $1, "\" },\n";
>> +    }
>> +}
>> +close IN_FILE || die;
> 
> Can this be done with sed? Do we really need Perl for this?
> 
In principle, sure. I just failed to stuff everything into a makefile
line, so perl was easier to code.

>> [ ... ]
>> +static const struct {
>> +	unsigned int	value;
>> +	char		*name;
> 
> Can 'char *' be changed into 'const char *'?
> 
Sure; why not.

>> +} sdev_bflags[] = {
>> +#include "scsi_devinfo_tbl.c"
>> +};
>> +
>> +static const char *sdev_bflags_name(unsigned int bflags)
>> +{
>> +	int i;
>> +	const char *name = NULL;
>> +
>> +	for (i = 0; i < ARRAY_SIZE(sdev_bflags); i++) {
>> +		if (sdev_bflags[i].value == bflags) {
>> +			name = sdev_bflags[i].name;
>> +			break;
>> +		}
>> +	}
>> +	return name;
>> +}
> 
> How about using ilog2() of the BLIST_* values as index of the table such that
> an array lookup can be used instead of a for-loop over the entire array?
> 
Not sure if that'll work. The BLIST_* values in fact form a sparse
array, so the lookup array 'sdev_bflags' actually an associative array.
And I dare not convert it to a normal array as then I couldn't to the
automatice table creation anymore.

So I'm not sure if ilog2 will save me anything here.

>> +
>>  static int check_set(unsigned long long *val, char *src)
>>  {
>>  	char *last;
>> @@ -955,6 +977,43 @@ static DEVICE_ATTR(queue_depth, S_IRUGO | S_IWUSR, sdev_show_queue_depth,
>>  }
>>  static DEVICE_ATTR(wwid, S_IRUGO, sdev_show_wwid, NULL);
>>  
>> +static ssize_t
>> +sdev_show_blacklist(struct device *dev, struct device_attribute *attr,
>> +		    char *buf)
>> +{
>> +	struct scsi_device *sdev = to_scsi_device(dev);
>> +	int i;
>> +	char *ptr = buf;
>> +	ssize_t len = 0;
>> +
>> +	for (i = 0; i < sizeof(unsigned int) * 8; i++) {
>> +		unsigned int bflags = (unsigned int)1 << i;
> 
> How about using 1U instead of (unsigned int)1?
> 
Yeah, ok.

>> +		ssize_t blen;
>> +		const char *name = NULL;
>> +
>> +		if (!(bflags & sdev->sdev_bflags))
>> +			continue;
>> +
>> +		if (ptr != buf) {
>> +			blen = snprintf(ptr, 2, " ");
>> +			ptr += blen;
>> +			len += blen;
>> +		}
> 
> Should this code check whether or not it overflows the output buffer @buf?
> 
Hmm. In principle, yes.
However, as we're only have a limited number of possible arguments and
hence a fixed upper limit of what we can print into the buffer I'm not
sure if that's required.
But I'll check.

>> +		name = sdev_bflags_name(bflags);
>> +		if (name)
>> +			blen = snprintf(ptr, strlen(name) + 1,
>> +					"%s", name);
>> +		else
>> +			blen = snprintf(ptr, 67, "INVALID_BIT(%d)", i);
>> +		ptr += blen;
>> +		len += blen;
>> +	}
> 
> Should this code check too whether or not it overflows the output buffer @buf?
> 
See above.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		   Teamlead Storage & Networking
hare@suse.de			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)

  reply	other threads:[~2017-08-30 10:51 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-29  8:49 [PATCHv4 0/5] Fixup blacklist handling Hannes Reinecke
2017-08-29  8:49 ` [PATCHv4 1/5] scsi_debug: allow to specify inquiry vendor and model Hannes Reinecke
2017-08-29  8:49 ` [PATCHv4 2/5] scsi: Export blacklist flags to sysfs Hannes Reinecke
2017-08-29 16:02   ` Bart Van Assche
2017-08-30 10:50     ` Hannes Reinecke [this message]
2017-08-30 15:39       ` Bart Van Assche
2017-08-30  0:10   ` kbuild test robot
2017-08-29  8:49 ` [PATCHv4 3/5] scsi_devinfo: Reformat blacklist flags Hannes Reinecke
2017-08-29 16:06   ` Bart Van Assche
2017-08-29  8:49 ` [PATCHv4 4/5] scsi_devinfo: Whitespace fixes Hannes Reinecke
2017-08-29  8:49 ` [PATCHv4 5/5] scsi_devinfo: fixup string compare Hannes Reinecke
2017-08-29 16:30   ` Bart Van Assche

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=9e7eb07d-7796-ace6-ee04-d88e22e730b0@suse.de \
    --to=hare@suse.de \
    --cc=Alan@suse.de \
    --cc=Bart.VanAssche@wdc.com \
    --cc=hare@suse.com \
    --cc=hch@lst.de \
    --cc=james.bottomley@hansenpartnership.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=stern@rowland.harvard.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.