All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Hannes Reinecke <hare@suse.de>,
	"Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Christoph Hellwig <hch@lst.de>,
	James Bottomley <james.bottomley@hansenpartnership.com>,
	Doug Gilbert <dgilbert@interlog.com>,
	linux-scsi@vger.kernel.org
Subject: Re: [PATCH] scsi_debug: implement 'sdebug_lun_format' and update max_lun
Date: Fri, 29 May 2020 06:59:56 -0700	[thread overview]
Message-ID: <d8e4690c-b7be-9aca-1a31-052ab93f4d01@acm.org> (raw)
In-Reply-To: <20200529133942.146413-1-hare@suse.de>

On 2020-05-29 06:39, Hannes Reinecke wrote:
> -/* If REPORT LUNS has luns >= 256 it can choose "flat space" (value 1)
> - * or "peripheral device" addressing (value 0) */
> +/* If REPORT LUNS has luns >= 256 it should choose "flat space" (value 1)
> + * instead of "peripheral device" addressing (value 0) */
>  #define SAM2_LUN_ADDRESS_METHOD 0

How about introducing an enumeration type instead of using #define?

>  /* SDEBUG_CANQUEUE is the maximum number of commands that can be queued
> @@ -666,6 +666,7 @@ static bool have_dif_prot;
>  static bool write_since_sync;
>  static bool sdebug_statistics = DEF_STATISTICS;
>  static bool sdebug_wp;
> +static int sdebug_lun_format = SAM2_LUN_ADDRESS_METHOD;

How about using an enumeration type instead of 'int'?

> +static ssize_t lun_format_show(struct device_driver *ddp, char *buf)
> +{
> +	return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_lun_format);
> +}

How about inserting a blank line after this function definition?

> +static ssize_t lun_format_store(struct device_driver *ddp, const char *buf,
> +				size_t count)
> +{
> +	int n;
> +	bool changed;
> +
> +	if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) {

Isn't the recommended coding style to place constants at the right side
of comparisons? How about leaving out the superfluous parentheses? Such
parentheses may hide bugs because these suppress compiler warnings about
using assignments in if-conditions.

> +		if (n > 2) {
> +			pr_warn("only formats 0 and 1 are supported\n");
> +			return -EINVAL;
> +		}

How about introducing a symbolic name for the constant '2'?


> +	if (sdebug_lun_format > 2) {
> +		pr_warn("Invalid LUN format %u, using default\n",
> +			sdebug_lun_format);
> +		sdebug_lun_format = SAM2_LUN_ADDRESS_METHOD;
> +	}

How about using a symbolic name instead of the constant '2'?

>  	if (sdebug_max_luns > 256) {
> -		pr_warn("max_luns can be no more than 256, use default\n");
> -		sdebug_max_luns = DEF_MAX_LUNS;
> +		if (sdebug_max_luns > 16384) {
> +			pr_warn("max_luns can be no more than 16384, use default\n");
> +			sdebug_max_luns = DEF_MAX_LUNS;
> +		}
> +		sdebug_lun_format = 1;
>  	}

How about changing the constant '1' into a symbolic name?

Thanks,

Bart.

  reply	other threads:[~2020-05-29 14:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-29 13:39 [PATCH] scsi_debug: implement 'sdebug_lun_format' and update max_lun Hannes Reinecke
2020-05-29 13:59 ` Bart Van Assche [this message]
2020-05-31 21:30 ` Douglas Gilbert

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=d8e4690c-b7be-9aca-1a31-052ab93f4d01@acm.org \
    --to=bvanassche@acm.org \
    --cc=dgilbert@interlog.com \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=james.bottomley@hansenpartnership.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /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.