Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 Feb 2018 07:51:22 -0800
From:      Chuck Tuffli <ctuffli@gmail.com>
To:        Ian Lepore <ian@freebsd.org>
Cc:        Alan Somers <asomers@freebsd.org>, src-committers@freebsd.org,  svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r329830 - head/sbin/nvmecontrol
Message-ID:  <CAKAYmML7hDC76gBTif6nO8gJ=V7Xx7Z0qgXD9_Ls5eP5kgZjyw@mail.gmail.com>
In-Reply-To: <1519322697.91697.138.camel@freebsd.org>
References:  <201802221747.w1MHlGJS032223@repo.freebsd.org> <1519322697.91697.138.camel@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Feb 22, 2018 at 10:04 AM, Ian Lepore <ian@freebsd.org> wrote:
> On Thu, 2018-02-22 at 17:47 +0000, Alan Somers wrote:
>> Author: asomers
>> Date: Thu Feb 22 17:47:16 2018
>> New Revision: 329830
>> URL: https://svnweb.freebsd.org/changeset/base/329830
>>
>> Log:
>>   nvmecontrol: fix build on amd64/clang
>>
>>   Broken by:  329824
>>   Sponsored by:       Spectra Logic Corp
>>
>> Modified:
>>   head/sbin/nvmecontrol/identify.c
>>
>> Modified: head/sbin/nvmecontrol/identify.c
>> ==============================================================================
>> --- head/sbin/nvmecontrol/identify.c  Thu Feb 22 17:09:26 2018        (r329829)
>> +++ head/sbin/nvmecontrol/identify.c  Thu Feb 22 17:47:16 2018        (r329830)
>> @@ -112,7 +112,7 @@ print_controller(struct nvme_controller_data *cdata)
>>       if (cdata->mdts == 0)
>>               printf("Unlimited\n");
>>       else
>> -             printf("%ld\n", PAGE_SIZE * (1 << cdata->mdts));
>> +             printf("%d\n", PAGE_SIZE * (1 << cdata->mdts));
>>       printf("Controller ID:              0x%02x\n", cdata->ctrlr_id);
>>       printf("\n");
>
> If cdata->mdts > 19 that'll overflow 32 bits.  I'm not sure if that can
> happen in the real world or not.  If so, maybe it'd be better to do
>
>   printf("%ju\n", PAGE_SIZE * ((uintmax_t)1 << cdata->mdts));
>
> -- Ian

Yes, MDTS is an 8 bit value and thus can overflow in the way you
describe, but typically, it is in the range of 5-12. Also note that
multiplying by PAGE_SIZE isn't quite correct as MDTS is in units of
the NVMe Controller's advertised minimum page size (i.e. CAP.MPSMIN).
Most Controllers will default to a value of 4096 for MPSMIN, so
practically, this code will usually work.

--chuck



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAKAYmML7hDC76gBTif6nO8gJ=V7Xx7Z0qgXD9_Ls5eP5kgZjyw>