mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] fix error return get/set_native_max functions
@ 2003-08-05 18:18 Andries.Brouwer
  2003-08-05 18:54 ` Bartlomiej Zolnierkiewicz
  0 siblings, 1 reply; 8+ messages in thread
From: Andries.Brouwer @ 2003-08-05 18:18 UTC (permalink / raw)
  To: akpm, torvalds; +Cc: linux-kernel

In ide-disk.c we have functions
  idedisk_read_native_max_address
  idedisk_read_native_max_address_ext
  idedisk_set_max_address
  idedisk_set_max_address_ext
that are documented as

 /*
  * Sets maximum virtual LBA address of the drive.
  * Returns new maximum virtual LBA address (> 0) or 0 on failure.
  */

The IDE command they execute returns the largest address,
and 1 is added to get the capacity.
Unfortunately, the code does

	addr = 0;
	if (ide_command_succeeds) {
		addr = ...
	}
	addr++;

so that the return value on error is 1 instead of 0.
The patch below moves the addr++.

Andries

diff -u --recursive --new-file -X /linux/dontdiff a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
--- a/drivers/ide/ide-disk.c	Mon Jul 28 05:39:23 2003
+++ b/drivers/ide/ide-disk.c	Tue Aug  5 21:00:34 2003
@@ -964,12 +964,13 @@
 		     | ((args.tfRegister[  IDE_HCYL_OFFSET]       ) << 16)
 		     | ((args.tfRegister[  IDE_LCYL_OFFSET]       ) <<  8)
 		     | ((args.tfRegister[IDE_SECTOR_OFFSET]       ));
+		addr++;	/* since the return value is (maxlba - 1), we add 1 */
 	}
-	addr++;	/* since the return value is (maxlba - 1), we add 1 */
 	return addr;
 }
 
-static unsigned long long idedisk_read_native_max_address_ext(ide_drive_t *drive)
+static unsigned long long
+idedisk_read_native_max_address_ext(ide_drive_t *drive)
 {
 	ide_task_t args;
 	unsigned long long addr = 0;
@@ -992,8 +993,8 @@
 			   ((args.tfRegister[IDE_LCYL_OFFSET])<<8) |
 			    (args.tfRegister[IDE_SECTOR_OFFSET]);
 		addr = ((__u64)high << 24) | low;
+		addr++;	/* since the return value is (maxlba - 1), we add 1 */
 	}
-	addr++;	/* since the return value is (maxlba - 1), we add 1 */
 	return addr;
 }
 
@@ -1002,7 +1003,8 @@
  * Sets maximum virtual LBA address of the drive.
  * Returns new maximum virtual LBA address (> 0) or 0 on failure.
  */
-static unsigned long idedisk_set_max_address(ide_drive_t *drive, unsigned long addr_req)
+static unsigned long
+idedisk_set_max_address(ide_drive_t *drive, unsigned long addr_req)
 {
 	ide_task_t args;
 	unsigned long addr_set = 0;
@@ -1024,12 +1026,13 @@
 			 | ((args.tfRegister[  IDE_HCYL_OFFSET]       ) << 16)
 			 | ((args.tfRegister[  IDE_LCYL_OFFSET]       ) <<  8)
 			 | ((args.tfRegister[IDE_SECTOR_OFFSET]       ));
+		addr_set++;
 	}
-	addr_set++;
 	return addr_set;
 }
 
-static unsigned long long idedisk_set_max_address_ext(ide_drive_t *drive, unsigned long long addr_req)
+static unsigned long long
+idedisk_set_max_address_ext(ide_drive_t *drive, unsigned long long addr_req)
 {
 	ide_task_t args;
 	unsigned long long addr_set = 0;
@@ -1059,6 +1062,7 @@
 			   ((args.tfRegister[IDE_LCYL_OFFSET])<<8) |
 			    (args.tfRegister[IDE_SECTOR_OFFSET]);
 		addr_set = ((__u64)high << 24) | low;
+		addr_set++;
 	}
 	return addr_set;
 }

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [PATCH] fix error return get/set_native_max functions
@ 2003-08-05 20:08 Andries.Brouwer
  2003-08-05 20:45 ` Bartlomiej Zolnierkiewicz
  2003-08-05 23:15 ` Roman Zippel
  0 siblings, 2 replies; 8+ messages in thread
From: Andries.Brouwer @ 2003-08-05 20:08 UTC (permalink / raw)
  To: Andries.Brouwer, B.Zolnierkiewicz; +Cc: linux-kernel

> This change is okay, thanks.
> However changing coding style is not...

An interesting remark.

I belong to the people who look at kernel source on a screen
with 80 columns. Code that is wider and wraps is unreadable.

Now of course you might react "buy a better monitor", but in fact
this restriction leads to cleaner code. There is something wrong
when code is indented too deeply, and almost always a cleanup is
possible that splits some inner stuff out as a separate function.

As a side effect of that you'll see in patches from me changes
that bring the code within the 80-column limit.

> -static unsigned long idedisk_set_max_address(ide_drive_t *drive, unsigned long addr_req)
> +static unsigned long
> +idedisk_set_max_address(ide_drive_t *drive, unsigned long addr_req)

It is a matter of taste precisely which transformation is best
in order to bring the source within the 80-column limit,
but having the type on the preceding line is very common
in the kernel source (and elsewhere), so among the possible
ways of splitting this line this is a very natural one.

I am not interested in a discussion about style, but will defend
the 80-column limit.

Andries


---
Functions should be short and sweet, and do just one thing.  They should
fit on one or two screenfuls of text (the ISO/ANSI screen size is 80x24,
as we all know), and do one thing and do that well.

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [PATCH] fix error return get/set_native_max functions
@ 2003-08-05 20:27 Andries.Brouwer
  2003-08-05 20:57 ` Bartlomiej Zolnierkiewicz
  0 siblings, 1 reply; 8+ messages in thread
From: Andries.Brouwer @ 2003-08-05 20:27 UTC (permalink / raw)
  To: Andries.Brouwer, B.Zolnierkiewicz; +Cc: linux-kernel

By the way, is your tree visible somewhere?

I have a giant patch with quite a lot of improvements and
minor bug fixes, all in the geometry / IDENTIFY area.
Usually I diff against Linus' most recent version, but we
already had one by Erik and two by me, and stuff overlaps,
and I do not yet see any of this in Linus' tree.
Usually I wait with sending the next until I see the previous
patch applied, but when there are many fragments that process
is excruciatingly slow. So, maybe I can come with a series of
patches against your tree?




^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [PATCH] fix error return get/set_native_max functions
@ 2003-08-06  7:09 Andries.Brouwer
  0 siblings, 0 replies; 8+ messages in thread
From: Andries.Brouwer @ 2003-08-06  7:09 UTC (permalink / raw)
  To: Andries.Brouwer, B.Zolnierkiewicz; +Cc: linux-kernel

> Giant patch? :( Can you split it?

Of course.

A moment ago I split off the third part. More will follow.
(1 was bookkeeping in sector_t, 2 was addr++ fix).

This third part takes code that was repeated three times,
namely a debugging printout of the IDENTIFY DEVICE result,
and leaves only a single copy, that moreover is a bit more correct.

One of the things that were wrong in the debugging part
is also wrong in the non-debugging part, namely the ordering
of the bitfields on a bigendian architecture.
Probably that will be the next installment.

Let me send this in four subparts.
Three parts that remove the debugging code, and one part
that adds a single copy, in a new file ide-identify.h
that contains stuff that will also correct and simplify
other code.

Andries

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

end of thread, other threads:[~2003-08-06  7:09 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-05 18:18 [PATCH] fix error return get/set_native_max functions Andries.Brouwer
2003-08-05 18:54 ` Bartlomiej Zolnierkiewicz
2003-08-05 20:08 Andries.Brouwer
2003-08-05 20:45 ` Bartlomiej Zolnierkiewicz
2003-08-05 23:15 ` Roman Zippel
2003-08-05 20:27 Andries.Brouwer
2003-08-05 20:57 ` Bartlomiej Zolnierkiewicz
2003-08-06  7:09 Andries.Brouwer

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

all inboxes | Powered by JetHome®