From: Tom Rini Date: Tue, 5 Sep 2017 21:08:46 -0400 Subject: [U-Boot] [PATCH 1/4] blk: Use macros for block device vendor/product/rev string size In-Reply-To: <1504497610-4775-1-git-send-email-bmeng.cn@gmail.com> References: <1504497610-4775-1-git-send-email-bmeng.cn@gmail.com> Message-ID: <20170906010846.GM17058@bill-the-cat> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Sun, Sep 03, 2017 at 09:00:07PM -0700, Bin Meng wrote: > So far these are using magic numbers. Replace them with macros. > > Signed-off-by: Bin Meng > --- > > include/blk.h | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/include/blk.h b/include/blk.h > index a106f9c..fced138 100644 > --- a/include/blk.h > +++ b/include/blk.h > @@ -36,6 +36,10 @@ enum if_type { > IF_TYPE_COUNT, /* Number of interface types */ > }; > > +#define BLK_VEN_SIZE 41 > +#define BLK_PRD_SIZE 21 > +#define BLK_REV_SIZE 9 > + > /* > * With driver model (CONFIG_BLK) this is uclass platform data, accessible > * with dev_get_uclass_platdata(dev) > @@ -60,9 +64,9 @@ struct blk_desc { > lbaint_t lba; /* number of blocks */ > unsigned long blksz; /* block size */ > int log2blksz; /* for convenience: log2(blksz) */ > - char vendor[40+1]; /* IDE model, SCSI Vendor */ > - char product[20+1]; /* IDE Serial no, SCSI product */ > - char revision[8+1]; /* firmware revision */ > + char vendor[BLK_VEN_SIZE]; /* device vendor string */ > + char product[BLK_PRD_SIZE]; /* device product number */ > + char revision[BLK_REV_SIZE]; /* firmware revision */ I think we should be using BLK_xxx_SIZE + 1 instead here and then it looks like at least 2/4 shows why, we start to copy to the end of a char buffer in, rather than ensuring we have string+NULL in each. That is why we use SIZE+1 here. Thanks! -- Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: