All of lore.kernel.org
 help / color / mirror / Atom feed
* ERR_PTR and PTR_ERR
@ 2010-05-16  8:58 ` Julia Lawall
  0 siblings, 0 replies; 8+ messages in thread
From: Julia Lawall @ 2010-05-16  8:58 UTC (permalink / raw)
  To: linux-kernel, kernel-janitors

I see a number of occurrences of code like the following:

 	if (IS_ERR(alg))
		return ERR_PTR(PTR_ERR(alg));

Is there any reason why the second line couldn't just be return alg?

julia

^ permalink raw reply	[flat|nested] 8+ messages in thread

* ERR_PTR and PTR_ERR
@ 2010-05-16  8:58 ` Julia Lawall
  0 siblings, 0 replies; 8+ messages in thread
From: Julia Lawall @ 2010-05-16  8:58 UTC (permalink / raw)
  To: linux-kernel, kernel-janitors

I see a number of occurrences of code like the following:

 	if (IS_ERR(alg))
		return ERR_PTR(PTR_ERR(alg));

Is there any reason why the second line couldn't just be return alg?

julia

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ERR_PTR and PTR_ERR
  2010-05-16  8:58 ` Julia Lawall
@ 2010-05-16  9:05   ` Julia Lawall
  -1 siblings, 0 replies; 8+ messages in thread
From: Julia Lawall @ 2010-05-16  9:05 UTC (permalink / raw)
  To: linux-kernel, kernel-janitors

On Sun, 16 May 2010, Julia Lawall wrote:

> I see a number of occurrences of code like the following:
> 
>  	if (IS_ERR(alg))
> 		return ERR_PTR(PTR_ERR(alg));
> 
> Is there any reason why the second line couldn't just be return alg?

Hmm, never mind.  It seems to address a type problem.

julia

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ERR_PTR and PTR_ERR
@ 2010-05-16  9:05   ` Julia Lawall
  0 siblings, 0 replies; 8+ messages in thread
From: Julia Lawall @ 2010-05-16  9:05 UTC (permalink / raw)
  To: linux-kernel, kernel-janitors

On Sun, 16 May 2010, Julia Lawall wrote:

> I see a number of occurrences of code like the following:
> 
>  	if (IS_ERR(alg))
> 		return ERR_PTR(PTR_ERR(alg));
> 
> Is there any reason why the second line couldn't just be return alg?

Hmm, never mind.  It seems to address a type problem.

julia

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ERR_PTR and PTR_ERR
  2010-05-16  9:05   ` Julia Lawall
@ 2010-05-16 17:37     ` Al Viro
  -1 siblings, 0 replies; 8+ messages in thread
From: Al Viro @ 2010-05-16 17:37 UTC (permalink / raw)
  To: Julia Lawall; +Cc: linux-kernel, kernel-janitors

On Sun, May 16, 2010 at 11:05:23AM +0200, Julia Lawall wrote:
> On Sun, 16 May 2010, Julia Lawall wrote:
> 
> > I see a number of occurrences of code like the following:
> > 
> >  	if (IS_ERR(alg))
> > 		return ERR_PTR(PTR_ERR(alg));
> > 
> > Is there any reason why the second line couldn't just be return alg?
> 
> Hmm, never mind.  It seems to address a type problem.

More idiomatic way to deal with that is ERR_CAST(); see e.g. ext2_lookup() for
use case:
	...
	inode = NULL;
	if (ino) {
		inode = ext2_iget(dir->i_sb, ino);
		if (unlikely(IS_ERR(inode))) {
			if (PTR_ERR(inode) = -ESTALE) {
				ext2_error(dir->i_sb, __func__,
						"deleted inode referenced: %lu",
						(unsigned long) ino);
				return ERR_PTR(-EIO);
			} else {
				return ERR_CAST(inode);
			}
		}
	}
	return d_splice_alias(inode, dentry);


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ERR_PTR and PTR_ERR
@ 2010-05-16 17:37     ` Al Viro
  0 siblings, 0 replies; 8+ messages in thread
From: Al Viro @ 2010-05-16 17:37 UTC (permalink / raw)
  To: Julia Lawall; +Cc: linux-kernel, kernel-janitors

On Sun, May 16, 2010 at 11:05:23AM +0200, Julia Lawall wrote:
> On Sun, 16 May 2010, Julia Lawall wrote:
> 
> > I see a number of occurrences of code like the following:
> > 
> >  	if (IS_ERR(alg))
> > 		return ERR_PTR(PTR_ERR(alg));
> > 
> > Is there any reason why the second line couldn't just be return alg?
> 
> Hmm, never mind.  It seems to address a type problem.

More idiomatic way to deal with that is ERR_CAST(); see e.g. ext2_lookup() for
use case:
	...
	inode = NULL;
	if (ino) {
		inode = ext2_iget(dir->i_sb, ino);
		if (unlikely(IS_ERR(inode))) {
			if (PTR_ERR(inode) == -ESTALE) {
				ext2_error(dir->i_sb, __func__,
						"deleted inode referenced: %lu",
						(unsigned long) ino);
				return ERR_PTR(-EIO);
			} else {
				return ERR_CAST(inode);
			}
		}
	}
	return d_splice_alias(inode, dentry);


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ERR_PTR and PTR_ERR
  2010-05-16 17:37     ` Al Viro
@ 2010-05-16 18:26       ` Julia Lawall
  -1 siblings, 0 replies; 8+ messages in thread
From: Julia Lawall @ 2010-05-16 18:26 UTC (permalink / raw)
  To: Al Viro; +Cc: linux-kernel, kernel-janitors

On Sun, 16 May 2010, Al Viro wrote:

> On Sun, May 16, 2010 at 11:05:23AM +0200, Julia Lawall wrote:
> > On Sun, 16 May 2010, Julia Lawall wrote:
> > 
> > > I see a number of occurrences of code like the following:
> > > 
> > >  	if (IS_ERR(alg))
> > > 		return ERR_PTR(PTR_ERR(alg));
> > > 
> > > Is there any reason why the second line couldn't just be return alg?
> > 
> > Hmm, never mind.  It seems to address a type problem.
> 
> More idiomatic way to deal with that is ERR_CAST(); see e.g. ext2_lookup() for
> use case:

Thanks.  That looks much nicer than ERR_PTR(PTR_ERR(alg)).

julia


> 	...
> 	inode = NULL;
> 	if (ino) {
> 		inode = ext2_iget(dir->i_sb, ino);
> 		if (unlikely(IS_ERR(inode))) {
> 			if (PTR_ERR(inode) = -ESTALE) {
> 				ext2_error(dir->i_sb, __func__,
> 						"deleted inode referenced: %lu",
> 						(unsigned long) ino);
> 				return ERR_PTR(-EIO);
> 			} else {
> 				return ERR_CAST(inode);
> 			}
> 		}
> 	}
> 	return d_splice_alias(inode, dentry);
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: ERR_PTR and PTR_ERR
@ 2010-05-16 18:26       ` Julia Lawall
  0 siblings, 0 replies; 8+ messages in thread
From: Julia Lawall @ 2010-05-16 18:26 UTC (permalink / raw)
  To: Al Viro; +Cc: linux-kernel, kernel-janitors

On Sun, 16 May 2010, Al Viro wrote:

> On Sun, May 16, 2010 at 11:05:23AM +0200, Julia Lawall wrote:
> > On Sun, 16 May 2010, Julia Lawall wrote:
> > 
> > > I see a number of occurrences of code like the following:
> > > 
> > >  	if (IS_ERR(alg))
> > > 		return ERR_PTR(PTR_ERR(alg));
> > > 
> > > Is there any reason why the second line couldn't just be return alg?
> > 
> > Hmm, never mind.  It seems to address a type problem.
> 
> More idiomatic way to deal with that is ERR_CAST(); see e.g. ext2_lookup() for
> use case:

Thanks.  That looks much nicer than ERR_PTR(PTR_ERR(alg)).

julia


> 	...
> 	inode = NULL;
> 	if (ino) {
> 		inode = ext2_iget(dir->i_sb, ino);
> 		if (unlikely(IS_ERR(inode))) {
> 			if (PTR_ERR(inode) == -ESTALE) {
> 				ext2_error(dir->i_sb, __func__,
> 						"deleted inode referenced: %lu",
> 						(unsigned long) ino);
> 				return ERR_PTR(-EIO);
> 			} else {
> 				return ERR_CAST(inode);
> 			}
> 		}
> 	}
> 	return d_splice_alias(inode, dentry);
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-05-16 18:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-16  8:58 ERR_PTR and PTR_ERR Julia Lawall
2010-05-16  8:58 ` Julia Lawall
2010-05-16  9:05 ` Julia Lawall
2010-05-16  9:05   ` Julia Lawall
2010-05-16 17:37   ` Al Viro
2010-05-16 17:37     ` Al Viro
2010-05-16 18:26     ` Julia Lawall
2010-05-16 18:26       ` Julia Lawall

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.