On Fri, 2007-03-16 at 12:10 -0400, Ming Zhang wrote: > On Fri, 2007-03-16 at 08:01 -0700, Randy Dunlap wrote: > > On Fri, 16 Mar 2007 10:11:37 -0400 Ming Zhang wrote: > > > > > On Fri, 2007-03-16 at 09:49 -0400, Avishay Traeger wrote: > > > > On Fri, 2007-03-16 at 09:36 -0400, Ming Zhang wrote: > > > > > On Thu, 2007-03-15 at 20:21 -0700, Randy Dunlap wrote: > > > > > > On Mon, 12 Mar 2007 13:23:07 -0400 Ming Zhang wrote: > > > > > > > > > > > > > Hi All > > > > > > > > > > > > > > I know sometime we need ERR_PTR and PTR_ERR, but why we need to write > > > > > > > code like this line 356 in quotactl_block() > > > > > > > > > > > > > > 353 bdev = lookup_bdev(tmp); > > > > > > > 354 putname(tmp); > > > > > > > 355 if (IS_ERR(bdev)) > > > > > > > 356 return ERR_PTR(PTR_ERR(bdev)) > > > > > > > > > > > > > > instead of > > > > > > > > > > > > > > return bdev > > > > > > > > > > > > > > it convert a PTR to ERR and then back to PTR. any idea why? > > > > > > > > > > > > Did you test what happens when you change that return line to be only > > > > > > return bdev; > > > > > > ? Please do so. > > > > > > > > > > sorry i should be more accurate. > > > > > > > > > > ERR_PTR(PTR_ERR(bdev)) is like to > > > > > > > > > > return (void *)(long)bdev; > > > > > > > > > > then what is the difference between this and > > > > > > > > > > return (void *)bdev; > > > > > > > > > > > > > > > from speed, this 2 should have no difference. then any other > > > > > consideration? > > > > > > > > This is a very good question, and I am curious about the answer. I was > > > > hoping that you would get an answer. Can you do Randy's suggestion, and > > > > change "ERR_PTR(PTR_ERR(bdev))" to "bdev", and see if it breaks? > > > > > > if simply return bdev, this will have a warning since function expects a > > > super_block*. so add a (void *) will remove that warning. other than > > > this, i can not see any trick here. > > > > Agreed. I think that it's just type coercion (casting) and type-checking. > > > > thanks. after a while, now i think the original code is less misleading > than simply add a (void *). casting a *bdev to *super_block can mislead > people. > > original code explicitly tell us that it will return a pointer and that > pointer only contain error info, just in a not that explicit way. ;) You don't need to cast *bdev to *super_block - you need to cast it to *void. I think that this: return ERR_PTR(PTR_ERR(bdev)); is more confusing than this: return (void *)bdev; My question is, are these two statements functionally identical? Avishay -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ