All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: mtd/drivers/mtd rfd_ftl.c,1.1,1.2
       [not found] <E1DlT1z-0001Si-DN@phoenix.infradead.org>
@ 2005-06-24 16:52 ` Jörn Engel
  0 siblings, 0 replies; only message in thread
From: Jörn Engel @ 2005-06-24 16:52 UTC (permalink / raw)
  To: sean; +Cc: linux-mtd

On Thu, 23 June 2005 15:50:15 +0100, sean@infradead.org wrote:
> +
> +	for (i=0; i<SECTOR_SIZE; i++) {
> +		if (buf[i])
> +			break;
> +	}
> +
> +	if (i < SECTOR_SIZE) {
> +		rc = do_writesect(dev, sector, buf, &old_addr);
> +		if (rc)
> +			goto err;
> +	}
> +	else 
> +		part->sector_map[sector] = -1;

I don't like this part too much.  Effectively, you're using "i" as a
state variable.  In this specific case, it's not too bad, but my
experience with state variable is that they always hurt.

Maybe something like this:

+	for (i=0; i<SECTOR_SIZE; i++) {
+		if (!buf[i])
+			continue;
+		rc = do_writesect(dev, sector, buf, &old_addr);
+		if (rc)
+			goto err;
+	}
+
+	if (i == SECTOR_SIZE)
+		part->sector_map[sector] = -1;

Or even:

+	for (i=0; i<SECTOR_SIZE; i++) {
+		if (!buf[i])
+			continue;
+		rc = do_writesect(dev, sector, buf, &old_addr);
+		if (rc)
+			goto err;
+		goto hit;
+	}
+
+	/* no hit */
+	part->sector_map[sector] = -1;
+hit:

Now we have one additional goto and your cs professor would fail you
in class, but code flow and data is nicely seperated.

Jörn

-- 
Mac is for working, 
Linux is for Networking, 
Windows is for Solitaire! 
-- stolen from dc

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-06-24 16:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <E1DlT1z-0001Si-DN@phoenix.infradead.org>
2005-06-24 16:52 ` mtd/drivers/mtd rfd_ftl.c,1.1,1.2 Jörn Engel

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.