2005-09-02 22:11:11

by Adrian Bunk

[permalink] [raw]
Subject: [2.6 patch] drivers/block/nbd.c: don't defer compile error to runtime

If we can detect a problem at compile time, the compilation should fail.


Signed-off-by: Adrian Bunk <[email protected]>

--- linux-2.6.13-mm1-full/drivers/block/nbd.c.old 2005-09-02 23:48:27.000000000 +0200
+++ linux-2.6.13-mm1-full/drivers/block/nbd.c 2005-09-02 23:53:47.000000000 +0200
@@ -644,8 +644,8 @@
int i;

if (sizeof(struct nbd_request) != 28) {
- printk(KERN_CRIT "nbd: sizeof nbd_request needs to be 28 in order to work!\n" );
- return -EIO;
+ extern void nbd_request_wrong_size(void);
+ nbd_request_wrong_size();
}

if (nbds_max > MAX_NBD) {


2005-09-02 22:53:54

by Adam Kropelin

[permalink] [raw]
Subject: Re: [2.6 patch] drivers/block/nbd.c: don't defer compile error to runtime

Adrian Bunk wrote:
> If we can detect a problem at compile time, the compilation should
> fail.

[...]

> if (sizeof(struct nbd_request) != 28) {
> - printk(KERN_CRIT "nbd: sizeof nbd_request needs to be 28 in order to work!\n" );
> - return -EIO;
> + extern void nbd_request_wrong_size(void);
> + nbd_request_wrong_size();

BUILD_BUG_ON(sizeof(struct nbd_request) != 28);

...perhaps?

--Adam

2005-09-02 23:24:14

by Adrian Bunk

[permalink] [raw]
Subject: [2.6 patch] drivers/block/nbd.c: don't defer compile error to runtime

On Fri, Sep 02, 2005 at 07:20:47PM -0400, Adam Kropelin wrote:
> Adrian Bunk wrote:
> > If we can detect a problem at compile time, the compilation should
> > fail.
>
> [...]
>
> > if (sizeof(struct nbd_request) != 28) {
> > - printk(KERN_CRIT "nbd: sizeof nbd_request needs to be 28 in order to work!\n" );
> > - return -EIO;
> > + extern void nbd_request_wrong_size(void);
> > + nbd_request_wrong_size();
>
> BUILD_BUG_ON(sizeof(struct nbd_request) != 28);
>
> ...perhaps?

Neat, I didn't know about this.

I didn't know about this.

> --Adam

cu
Adrian


<-- snip -->


If we can detect a problem at compile time, the compilation should fail.


Signed-off-by: Adrian Bunk <[email protected]>

--- linux-2.6.13-mm1-full/drivers/block/nbd.c.old 2005-09-02 23:48:27.000000000 +0200
+++ linux-2.6.13-mm1-full/drivers/block/nbd.c 2005-09-03 01:08:04.000000000 +0200
@@ -643,10 +643,7 @@
int err = -ENOMEM;
int i;

- if (sizeof(struct nbd_request) != 28) {
- printk(KERN_CRIT "nbd: sizeof nbd_request needs to be 28 in order to work!\n" );
- return -EIO;
- }
+ BUILD_BUG_ON(sizeof(struct nbd_request) != 28);

if (nbds_max > MAX_NBD) {
printk(KERN_CRIT "nbd: cannot allocate more than %u nbds; %u requested.\n", MAX_NBD,