2002-12-12 23:19:57

by Hollis Blanchard

[permalink] [raw]
Subject: [PATCH] BIN_TO_BCD consolidation

All I wanted to do was "secal = BIN_TO_BCD(secs % 60)" ...

Has anyone else noticed the number of BCD_TO_BIN / BIN_TO_BCD
definitions?
egrep -lr -e "define (BCD_TO_BIN|BIN_TO_BCD)" linux/

Definitions are all over (in arch C files, arch includes, generic
includes, even a SCSI C file). They're all identical. They're almost all
wrapped with #ifndef to keep from clobbering each other.

My biggest problem is that they make an assignment:
#define BIN_TO_BCD(val) ((val)=(((val)/10)<<4) + (val)%10)
This makes it impossible to write code like
secal = BIN_TO_BCD(secs % 60);
because 'secs % 60' is not an lvalue.

The following patch moves all those definitions into include/linux/bcd.h
and defines BIN2BCD which doesn't make an assignment. I don't care what
it's called if that offends anyone; I just want to be able to do it. I'd
like to see BIN_TO_BCD deprecated, but maybe that's just me.

I tried to catch everything; I apologize if I missed an instance or two.
Obviously I couldn't test it all, but it builds on PPC. Comments?

-Hollis
--
PowerPC Linux
IBM Linux Technology Center

arch/alpha/kernel/time.c | 1 +
arch/arm/kernel/time.c | 8 --------
arch/cris/drivers/ds1302.c | 1 +
arch/cris/kernel/time.c | 1 +
arch/i386/kernel/time.c | 1 +
arch/m68k/atari/time.c | 1 +
arch/m68k/sun3x/time.c | 4 +---
arch/mips/ddb5xxx/common/rtc_ds1386.c | 7 +------
arch/mips/dec/time.c | 1 +
arch/mips/kernel/old-time.c | 1 +
arch/mips64/sgi-ip27/ip27-rtc.c | 1 +
arch/mips64/sgi-ip27/ip27-timer.c | 1 +
arch/ppc/iSeries/mf.c | 1 +
arch/ppc/platforms/chrp_time.c | 1 +
arch/ppc/platforms/gemini_setup.c | 1 +
arch/ppc/platforms/prep_time.c | 1 +
arch/ppc/syslib/todc_time.c | 1 +
arch/ppc64/kernel/mf.c | 1 +
arch/ppc64/kernel/rtc.c | 1 +
arch/sh/kernel/rtc.c | 9 +--------
arch/sparc64/kernel/time.c | 9 +--------
arch/x86_64/kernel/time.c | 1 +
drivers/acorn/char/pcf8583.c | 1 +
drivers/acpi/sleep.c | 1 +
drivers/char/rtc.c | 1 +
drivers/scsi/sr_vendor.c | 3 +--
drivers/sgi/char/ds1286.c | 1 +
include/asm-arm/arch-ebsa285/time.h | 1 +
include/asm-cris/rtc.h | 5 -----
include/asm-generic/rtc.h | 1 +
include/asm-mips/ds1286.h | 11 -----------
include/asm-mips64/ds1286.h | 11 -----------
include/asm-mips64/m48t35.h | 8 --------
include/asm-ppc/m48t35.h | 9 ---------
include/asm-ppc/mk48t59.h | 8 --------
include/asm-ppc/nvram.h | 8 --------
include/asm-ppc/todc.h | 8 --------
include/asm-ppc64/nvram.h | 8 --------
include/linux/bcd.h | 20 ++++++++++++++++++++
include/linux/mc146818rtc.h | 11 -----------
40 files changed, 48 insertions(+), 122 deletions(-)


Attachments:
bcd-consolidate.diff (19.66 kB)
signature.asc (189.00 B)
This is a digitally signed message part
Download all attachments