From: Tony Lindgren Date: Tue, 23 Aug 2016 15:21:25 -0700 Subject: [U-Boot] [PATCH] nand: Fix set_dev checks for no device In-Reply-To: <1471990037.25630.279.camel@buserror.net> References: <20160823212621.r6absphhojmfulr4@atomide.com> <1471987839.25630.277.camel@buserror.net> <20160823220442.zv3guwtetvua5lf3@atomide.com> <1471990037.25630.279.camel@buserror.net> Message-ID: <20160823222125.ihfaeqwezo3s3qz4@atomide.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de * Scott Wood [160823 15:08]: > On Tue, 2016-08-23 at 15:04 -0700, Tony Lindgren wrote: > > * Scott Wood [160823 14:31]: > > > > > > On Tue, 2016-08-23 at 14:26 -0700, Tony Lindgren wrote: > > > > > > > > If we do nand device 0 command in u-boot on a device that has NAND > > > > support > > > > enabled but no NAND chip, we can get data abort at least on omaps. > > > > > > > > Fix the issue by adding a check for nand_info[dev]. > > > > > > > > Signed-off-by: Tony Lindgren > > > > --- a/cmd/nand.c > > > > +++ b/cmd/nand.c > > > > @@ -116,7 +116,7 @@ free_dat: > > > > ?static int set_dev(int dev) > > > > ?{ > > > > ? if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE || > > > > - ????!nand_info[dev]->name) { > > > > + ????!nand_info[dev] || !nand_info[dev]->name) { > > > > ? puts("No such device\n"); > > > > ? return -1; > > > > ? } > > > The new !nand_info[dev] check can replace the old name check (similarly to > > > how > > > commit?4cc9699be7ffc replaced the old zero-blocksize check). > > Do you mean we can now leave out the test for !nand_info[dev]->name > > in set_dev() with this patch? > > Yes. ?It existed before because before the array-to-pointer conversion there > was no way to directly test nand_info[dev] for emptiness. OK seems to work. Updated patch below. Regards, Tony 8< ----------------- From: Tony Lindgren Date: Tue, 23 Aug 2016 15:14:26 -0700 Subject: [PATCHv2] nand: Fix set_dev checks for no device If we do nand device 0 command in u-boot on a device that has NAND support enabled but no NAND chip, we can get data abort at least on omaps. Fix the issue by replaceing the check with nand_info[dev] as suggested by Scott Wood. The check for name existed before because before the array-to-pointer conversion there was no way to directly test nand_info[dev] for emptiness. Signed-off-by: Tony Lindgren --- a/cmd/nand.c +++ b/cmd/nand.c @@ -115,8 +115,7 @@ free_dat: static int set_dev(int dev) { - if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE || - !nand_info[dev]->name) { + if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE || !nand_info[dev]) { puts("No such device\n"); return -1; }