Skip to contentSkip to conversation

drivers/block/nbd.c: don't defer compile error to runtime

PATCH In review Adrian Bunk 2 participants 3 messages Sep 2, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/block/nbd.c: don't defer compile error to runtime

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

drivers/block/nbd.c renamed from drivers/block/nbd.c.old +2 -2
@@ -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) {
#1 lore raw
Quoted 2 lines · Adrian Bunk

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

[...]

drivers/block/nbd.c line 648

Quoted 5 lines
drivers/block/nbd.c renamed from drivers/block/nbd.c.old +2 -2
 	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

#2 lore raw

PATCH 1/1 drivers/block/nbd.c: don't defer compile error to runtime

Quoted 14 lines · Adam Kropelin
Quoted 2 lines · Adrian Bunk

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

[...]

Review

Quoted 5 lines
(quoted diff) +2 -2
 	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);
Quoted 1 line

...perhaps?

Neat, I didn't know about this.

I didn't know about this.

Quoted 1 line

--Adam

cu
Adrian

<-- snip -->

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

drivers/block/nbd.c renamed from drivers/block/nbd.c.old +1 -4
@@ -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,