public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [S390] cio: Make ccw_dev_id_is_equal() more robust.
@ 2006-12-04 14:56 Martin Schwidefsky
  2006-12-04 15:23 ` Josef Sipek
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Schwidefsky @ 2006-12-04 14:56 UTC (permalink / raw)
  To: linux-kernel, cornelia.huck

From: Cornelia Huck <cornelia.huck@de.ibm.com>

[S390] cio: Make ccw_dev_id_is_equal() more robust.

Using memcmp to compare ccw_dev_id implies that the whole structure (incl.
padding) has always been completely initialized to sane values. Comparing
the structures field by field doesn't make such assumptions.

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
---

 include/asm-s390/cio.h |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletion(-)

diff -urpN linux-2.6/include/asm-s390/cio.h linux-2.6-patched/include/asm-s390/cio.h
--- linux-2.6/include/asm-s390/cio.h	2006-12-04 14:50:48.000000000 +0100
+++ linux-2.6-patched/include/asm-s390/cio.h	2006-12-04 14:51:00.000000000 +0100
@@ -278,7 +278,10 @@ struct ccw_dev_id {
 static inline int ccw_dev_id_is_equal(struct ccw_dev_id *dev_id1,
 				      struct ccw_dev_id *dev_id2)
 {
-	return !memcmp(dev_id1, dev_id2, sizeof(struct ccw_dev_id));
+	if ((dev_id1->ssid == dev_id2->ssid) &&
+	    (dev_id1->devno == dev_id2->devno))
+		return 1;
+	return 0;
 }
 
 extern int diag210(struct diag210 *addr);

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

* Re: [S390] cio: Make ccw_dev_id_is_equal() more robust.
  2006-12-04 14:56 [S390] cio: Make ccw_dev_id_is_equal() more robust Martin Schwidefsky
@ 2006-12-04 15:23 ` Josef Sipek
  2006-12-04 15:30   ` Martin Schwidefsky
  0 siblings, 1 reply; 3+ messages in thread
From: Josef Sipek @ 2006-12-04 15:23 UTC (permalink / raw)
  To: Martin Schwidefsky; +Cc: linux-kernel, cornelia.huck

On Mon, Dec 04, 2006 at 03:56:24PM +0100, Martin Schwidefsky wrote:
... 
> diff -urpN linux-2.6/include/asm-s390/cio.h linux-2.6-patched/include/asm-s390/cio.h
> --- linux-2.6/include/asm-s390/cio.h	2006-12-04 14:50:48.000000000 +0100
> +++ linux-2.6-patched/include/asm-s390/cio.h	2006-12-04 14:51:00.000000000 +0100
> @@ -278,7 +278,10 @@ struct ccw_dev_id {
>  static inline int ccw_dev_id_is_equal(struct ccw_dev_id *dev_id1,
>  				      struct ccw_dev_id *dev_id2)
>  {
> -	return !memcmp(dev_id1, dev_id2, sizeof(struct ccw_dev_id));
> +	if ((dev_id1->ssid == dev_id2->ssid) &&
> +	    (dev_id1->devno == dev_id2->devno))
> +		return 1;
> +	return 0;
>  }

Why not just:

return ((dev_id1->ssid == ......) && (...));

?

Josef "Jeff" Sipek.

-- 
UNIX is user-friendly ... it's just selective about who it's friends are

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

* Re: [S390] cio: Make ccw_dev_id_is_equal() more robust.
  2006-12-04 15:23 ` Josef Sipek
@ 2006-12-04 15:30   ` Martin Schwidefsky
  0 siblings, 0 replies; 3+ messages in thread
From: Martin Schwidefsky @ 2006-12-04 15:30 UTC (permalink / raw)
  To: Josef Sipek; +Cc: linux-kernel, cornelia.huck

On Mon, 2006-12-04 at 10:23 -0500, Josef Sipek wrote:
> > diff -urpN linux-2.6/include/asm-s390/cio.h linux-2.6-patched/include/asm-s390/cio.h
> > --- linux-2.6/include/asm-s390/cio.h	2006-12-04 14:50:48.000000000 +0100
> > +++ linux-2.6-patched/include/asm-s390/cio.h	2006-12-04 14:51:00.000000000 +0100
> > @@ -278,7 +278,10 @@ struct ccw_dev_id {
> >  static inline int ccw_dev_id_is_equal(struct ccw_dev_id *dev_id1,
> >  				      struct ccw_dev_id *dev_id2)
> >  {
> > -	return !memcmp(dev_id1, dev_id2, sizeof(struct ccw_dev_id));
> > +	if ((dev_id1->ssid == dev_id2->ssid) &&
> > +	    (dev_id1->devno == dev_id2->devno))
> > +		return 1;
> > +	return 0;
> >  }
> 
> Why not just:
> 
> return ((dev_id1->ssid == ......) && (...));

Yes, why not. It would be a little bit shorter. The compiler probably
won't care and generate the same code..

-- 
blue skies,
  Martin.

Martin Schwidefsky
Linux for zSeries Development & Services
IBM Deutschland Entwicklung GmbH

"Reality continues to ruin my life." - Calvin.



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

end of thread, other threads:[~2006-12-04 15:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-04 14:56 [S390] cio: Make ccw_dev_id_is_equal() more robust Martin Schwidefsky
2006-12-04 15:23 ` Josef Sipek
2006-12-04 15:30   ` Martin Schwidefsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox