[PATCH] [MTD] block2mtd.c: Make kernel boot command line arguments work (try 3)

Ville Herva vherva at vianova.fi
Tue Jul 11 02:23:42 EDT 2006


Few notes about the admittedly ugly #ifndef MODULE chunks:

On Fri, Jul 07, 2006 at 03:22:21PM +0300, you [Ville Herva] wrote:
> 
> --- linux-mtd-GIT/drivers/mtd/devices/block2mtd.c	2006-07-05 23:06:10.000000000 +0300
> +++ linux-2.6.17.3.NEW3/drivers/mtd/devices/block2mtd.c	2006-07-07 15:04:48.000000000 +0300
> 	bdev = open_bdev_excl(devname, O_RDWR, NULL);
> +#ifndef MODULE
> +		dev_t dev = name_to_dev_t(devname);
> +#endif

Apparently, name_to_dev_t() is not exported to use in modules (which kind of
makes sense - there shouldn't be need as rootfs should already be available
when a module is being loaded.) So I had to #ifdef it. And on the other
hand, open_bdev_excl() should be enough for modules anyway.

> +#ifndef MODULE
> +static int block2mtd_init_called = 0;
> +static __initdata char block2mtd_paramline[80 + 12]; /* 80 for device, 12 for erase size */
> +#endif

The __initdata variable gave warnings when compiling with -DMODULE (it was
referred, but not on a possible call path.) I decided to #ifdef it away, and
take block2mtd_init_called away as well. At least this saves some memory.

> +{
> +#ifdef MODULE
> +	return block2mtd_setup2(val);
> +#else
> +	if (block2mtd_init_called)
> +		return block2mtd_setup2(val);
> +	strlcpy(block2mtd_paramline, val, sizeof(block2mtd_paramline));
> +	return 0;
> +#endif

This should make sure that the behaviour is exactly the same as before in
-DMODULE and echo XX > /sys/module/block2mtd/parameters/block2mtd cases.
Specifically, static char block2mtd_paramline[80 + 12]; instruduced an
additional 92 char upper limit for the device name len. With the new patch,
this limit is only introduced for the kernel boot param (kernel internal
name_to_dev_t() probably won't accept anything longer anyway, but
open_bdev_excl() might, as it takes paths to the filesystem.)

Jörn, the #ifdef MODULE do clutter up the code, so I leave it to you as the
maintainer to decide if they are worth it.




More information about the linux-mtd mailing list