Skip to content

Commit

Permalink
drivers/firmware: const-ify DMI API and internals
Browse files Browse the repository at this point in the history
Three main sets of changes:

1) dmi_get_system_info() return value should have been marked const,
   since callers should not be changing that data.

2) const-ify DMI internals, since DMI firmware tables should,
   whenever possible, be marked const to ensure we never ever write to
   that data area.

3) const-ify DMI API, to enable marking tables const where possible
   in low-level drivers.

And if we're really lucky, this might enable some additional
optimizations on the part of the compiler.

The bulk of the changes are #2 and #3, which are interrelated.  #1 could
have been a separate patch, but it was so small compared to the others,
it was easier to roll it into this changeset.

Signed-off-by: Jeff Garzik <[email protected]>
  • Loading branch information
Jeff Garzik committed Oct 10, 2007
1 parent bbf2501 commit 1855256
Show file tree
Hide file tree
Showing 35 changed files with 103 additions and 97 deletions.
8 changes: 4 additions & 4 deletions arch/i386/kernel/acpi/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ static void __init acpi_process_madt(void)

#ifdef __i386__

static int __init disable_acpi_irq(struct dmi_system_id *d)
static int __init disable_acpi_irq(const struct dmi_system_id *d)
{
if (!acpi_force) {
printk(KERN_NOTICE "%s detected: force use of acpi=noirq\n",
Expand All @@ -917,7 +917,7 @@ static int __init disable_acpi_irq(struct dmi_system_id *d)
return 0;
}

static int __init disable_acpi_pci(struct dmi_system_id *d)
static int __init disable_acpi_pci(const struct dmi_system_id *d)
{
if (!acpi_force) {
printk(KERN_NOTICE "%s detected: force use of pci=noacpi\n",
Expand All @@ -927,7 +927,7 @@ static int __init disable_acpi_pci(struct dmi_system_id *d)
return 0;
}

static int __init dmi_disable_acpi(struct dmi_system_id *d)
static int __init dmi_disable_acpi(const struct dmi_system_id *d)
{
if (!acpi_force) {
printk(KERN_NOTICE "%s detected: acpi off\n", d->ident);
Expand All @@ -942,7 +942,7 @@ static int __init dmi_disable_acpi(struct dmi_system_id *d)
/*
* Limit ACPI to CPU enumeration for HT
*/
static int __init force_acpi_ht(struct dmi_system_id *d)
static int __init force_acpi_ht(const struct dmi_system_id *d)
{
if (!acpi_force) {
printk(KERN_NOTICE "%s detected: force use of acpi=ht\n",
Expand Down
2 changes: 1 addition & 1 deletion arch/i386/kernel/acpi/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ __setup("acpi_sleep=", acpi_sleep_setup);

/* Ouch, we want to delete this. We already have better version in userspace, in
s2ram from suspend.sf.net project */
static __init int reset_videomode_after_s3(struct dmi_system_id *d)
static __init int reset_videomode_after_s3(const struct dmi_system_id *d)
{
acpi_realmode_flags |= 2;
return 0;
Expand Down
18 changes: 9 additions & 9 deletions arch/i386/kernel/apm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1869,7 +1869,7 @@ static struct miscdevice apm_device = {


/* Simple "print if true" callback */
static int __init print_if_true(struct dmi_system_id *d)
static int __init print_if_true(const struct dmi_system_id *d)
{
printk("%s\n", d->ident);
return 0;
Expand All @@ -1879,14 +1879,14 @@ static int __init print_if_true(struct dmi_system_id *d)
* Some Bioses enable the PS/2 mouse (touchpad) at resume, even if it was
* disabled before the suspend. Linux used to get terribly confused by that.
*/
static int __init broken_ps2_resume(struct dmi_system_id *d)
static int __init broken_ps2_resume(const struct dmi_system_id *d)
{
printk(KERN_INFO "%s machine detected. Mousepad Resume Bug workaround hopefully not needed.\n", d->ident);
return 0;
}

/* Some bioses have a broken protected mode poweroff and need to use realmode */
static int __init set_realmode_power_off(struct dmi_system_id *d)
static int __init set_realmode_power_off(const struct dmi_system_id *d)
{
if (apm_info.realmode_power_off == 0) {
apm_info.realmode_power_off = 1;
Expand All @@ -1896,7 +1896,7 @@ static int __init set_realmode_power_off(struct dmi_system_id *d)
}

/* Some laptops require interrupts to be enabled during APM calls */
static int __init set_apm_ints(struct dmi_system_id *d)
static int __init set_apm_ints(const struct dmi_system_id *d)
{
if (apm_info.allow_ints == 0) {
apm_info.allow_ints = 1;
Expand All @@ -1906,7 +1906,7 @@ static int __init set_apm_ints(struct dmi_system_id *d)
}

/* Some APM bioses corrupt memory or just plain do not work */
static int __init apm_is_horked(struct dmi_system_id *d)
static int __init apm_is_horked(const struct dmi_system_id *d)
{
if (apm_info.disabled == 0) {
apm_info.disabled = 1;
Expand All @@ -1915,7 +1915,7 @@ static int __init apm_is_horked(struct dmi_system_id *d)
return 0;
}

static int __init apm_is_horked_d850md(struct dmi_system_id *d)
static int __init apm_is_horked_d850md(const struct dmi_system_id *d)
{
if (apm_info.disabled == 0) {
apm_info.disabled = 1;
Expand All @@ -1927,7 +1927,7 @@ static int __init apm_is_horked_d850md(struct dmi_system_id *d)
}

/* Some APM bioses hang on APM idle calls */
static int __init apm_likes_to_melt(struct dmi_system_id *d)
static int __init apm_likes_to_melt(const struct dmi_system_id *d)
{
if (apm_info.forbid_idle == 0) {
apm_info.forbid_idle = 1;
Expand All @@ -1951,7 +1951,7 @@ static int __init apm_likes_to_melt(struct dmi_system_id *d)
* Phoenix A04 08/24/2000 is known bad (Dell Inspiron 5000e)
* Phoenix A07 09/29/2000 is known good (Dell Inspiron 5000)
*/
static int __init broken_apm_power(struct dmi_system_id *d)
static int __init broken_apm_power(const struct dmi_system_id *d)
{
apm_info.get_power_status_broken = 1;
printk(KERN_WARNING "BIOS strings suggest APM bugs, disabling power status reporting.\n");
Expand All @@ -1962,7 +1962,7 @@ static int __init broken_apm_power(struct dmi_system_id *d)
* This bios swaps the APM minute reporting bytes over (Many sony laptops
* have this problem).
*/
static int __init swab_apm_power_in_minutes(struct dmi_system_id *d)
static int __init swab_apm_power_in_minutes(const struct dmi_system_id *d)
{
apm_info.get_power_status_swabinminutes = 1;
printk(KERN_WARNING "BIOS strings suggest APM reports battery life in minutes and wrong byte order.\n");
Expand Down
4 changes: 2 additions & 2 deletions arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,13 +533,13 @@ static int __init acpi_cpufreq_early_init(void)
*/
static int bios_with_sw_any_bug;

static int sw_any_bug_found(struct dmi_system_id *d)
static int sw_any_bug_found(const struct dmi_system_id *d)
{
bios_with_sw_any_bug = 1;
return 0;
}

static struct dmi_system_id sw_any_bug_dmi_table[] = {
static const struct dmi_system_id sw_any_bug_dmi_table[] = {
{
.callback = sw_any_bug_found,
.ident = "Supermicro Server X6DLP",
Expand Down
2 changes: 1 addition & 1 deletion arch/i386/kernel/reboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ __setup("reboot=", reboot_setup);
/*
* Some machines require the "reboot=b" commandline option, this quirk makes that automatic.
*/
static int __init set_bios_reboot(struct dmi_system_id *d)
static int __init set_bios_reboot(const struct dmi_system_id *d)
{
if (!reboot_thru_bios) {
reboot_thru_bios = 1;
Expand Down
2 changes: 1 addition & 1 deletion arch/i386/kernel/tsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ void mark_tsc_unstable(char *reason)
}
EXPORT_SYMBOL_GPL(mark_tsc_unstable);

static int __init dmi_mark_tsc_unstable(struct dmi_system_id *d)
static int __init dmi_mark_tsc_unstable(const struct dmi_system_id *d)
{
printk(KERN_NOTICE "%s detected: marking TSC unstable.\n",
d->ident);
Expand Down
4 changes: 2 additions & 2 deletions arch/i386/mach-generic/bigsmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

static int dmi_bigsmp; /* can be set by dmi scanners */

static int hp_ht_bigsmp(struct dmi_system_id *d)
static int hp_ht_bigsmp(const struct dmi_system_id *d)
{
#ifdef CONFIG_X86_GENERICARCH
printk(KERN_NOTICE "%s detected: force use of apic=bigsmp\n", d->ident);
Expand All @@ -31,7 +31,7 @@ static int hp_ht_bigsmp(struct dmi_system_id *d)
}


static struct dmi_system_id bigsmp_dmi_table[] = {
static const struct dmi_system_id bigsmp_dmi_table[] = {
{ hp_ht_bigsmp, "HP ProLiant DL760 G2", {
DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
DMI_MATCH(DMI_BIOS_VERSION, "P44-"),
Expand Down
4 changes: 2 additions & 2 deletions arch/i386/pci/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void __devinit pcibios_fixup_bus(struct pci_bus *b)
* on the kernel command line (which was parsed earlier).
*/

static int __devinit set_bf_sort(struct dmi_system_id *d)
static int __devinit set_bf_sort(const struct dmi_system_id *d)
{
if (pci_bf_sort == pci_bf_sort_default) {
pci_bf_sort = pci_dmi_bf;
Expand All @@ -136,7 +136,7 @@ static int __devinit set_bf_sort(struct dmi_system_id *d)
* Enable renumbering of PCI bus# ranges to reach all PCI busses (Cardbus)
*/
#ifdef __i386__
static int __devinit assign_all_busses(struct dmi_system_id *d)
static int __devinit assign_all_busses(const struct dmi_system_id *d)
{
pci_probe |= PCI_ASSIGN_ALL_BUSSES;
printk(KERN_INFO "%s detected: enabling PCI bus# renumbering"
Expand Down
4 changes: 2 additions & 2 deletions arch/i386/pci/irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ static void __init pcibios_fixup_irqs(void)
* Work around broken HP Pavilion Notebooks which assign USB to
* IRQ 9 even though it is actually wired to IRQ 11
*/
static int __init fix_broken_hp_bios_irq9(struct dmi_system_id *d)
static int __init fix_broken_hp_bios_irq9(const struct dmi_system_id *d)
{
if (!broken_hp_bios_irq9) {
broken_hp_bios_irq9 = 1;
Expand All @@ -1023,7 +1023,7 @@ static int __init fix_broken_hp_bios_irq9(struct dmi_system_id *d)
* Work around broken Acer TravelMate 360 Notebooks which assign
* Cardbus to IRQ 11 even though it is actually wired to IRQ 10
*/
static int __init fix_acer_tm360_irqrouting(struct dmi_system_id *d)
static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
{
if (!acer_tm360_irqrouting) {
acer_tm360_irqrouting = 1;
Expand Down
2 changes: 1 addition & 1 deletion drivers/acpi/osl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ acpi_os_validate_address (
}

#ifdef CONFIG_DMI
static int dmi_osi_linux(struct dmi_system_id *d)
static int dmi_osi_linux(const struct dmi_system_id *d)
{
printk(KERN_NOTICE "%s detected: enabling _OSI(Linux)\n", d->ident);
enable_osi_linux(1);
Expand Down
2 changes: 1 addition & 1 deletion drivers/acpi/processor_idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ module_param(bm_history, uint, 0644);
*
* To skip this limit, boot/load with a large max_cstate limit.
*/
static int set_max_cstate(struct dmi_system_id *id)
static int set_max_cstate(const struct dmi_system_id *id)
{
if (max_cstate > ACPI_PROCESSOR_MAX_POWER)
return 0;
Expand Down
2 changes: 1 addition & 1 deletion drivers/acpi/sleep/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ static struct pm_ops acpi_pm_ops = {
* Toshiba fails to preserve interrupts over S1, reinitialization
* of 8259 is needed after S1 resume.
*/
static int __init init_ints_after_s1(struct dmi_system_id *d)
static int __init init_ints_after_s1(const struct dmi_system_id *d)
{
printk(KERN_WARNING "%s with broken S1 detected.\n", d->ident);
init_8259A_after_S1 = 1;
Expand Down
8 changes: 4 additions & 4 deletions drivers/acpi/thermal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ static int acpi_thermal_resume(struct acpi_device *device)
}

#ifdef CONFIG_DMI
static int thermal_act(struct dmi_system_id *d) {
static int thermal_act(const struct dmi_system_id *d) {

if (act == 0) {
printk(KERN_NOTICE "ACPI: %s detected: "
Expand All @@ -1369,14 +1369,14 @@ static int thermal_act(struct dmi_system_id *d) {
}
return 0;
}
static int thermal_nocrt(struct dmi_system_id *d) {
static int thermal_nocrt(const struct dmi_system_id *d) {

printk(KERN_NOTICE "ACPI: %s detected: "
"disabling all critical thermal trip point actions.\n", d->ident);
nocrt = 1;
return 0;
}
static int thermal_tzp(struct dmi_system_id *d) {
static int thermal_tzp(const struct dmi_system_id *d) {

if (tzp == 0) {
printk(KERN_NOTICE "ACPI: %s detected: "
Expand All @@ -1385,7 +1385,7 @@ static int thermal_tzp(struct dmi_system_id *d) {
}
return 0;
}
static int thermal_psv(struct dmi_system_id *d) {
static int thermal_psv(const struct dmi_system_id *d) {

if (psv == 0) {
printk(KERN_NOTICE "ACPI: %s detected: "
Expand Down
4 changes: 2 additions & 2 deletions drivers/ata/ata_piix.c
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ static void ich_set_dmamode (struct ata_port *ap, struct ata_device *adev)
#ifdef CONFIG_PM
static int piix_broken_suspend(void)
{
static struct dmi_system_id sysids[] = {
static const struct dmi_system_id sysids[] = {
{
.ident = "TECRA M3",
.matches = {
Expand Down Expand Up @@ -1183,7 +1183,7 @@ static void __devinit piix_init_sata_map(struct pci_dev *pdev,

static void piix_iocfg_bit18_quirk(struct pci_dev *pdev)
{
static struct dmi_system_id sysids[] = {
static const struct dmi_system_id sysids[] = {
{
/* Clevo M570U sets IOCFG bit 18 if the cdrom
* isn't used to boot the system which
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/pata_ali.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* Cable special cases
*/

static struct dmi_system_id cable_dmi_table[] = {
static const struct dmi_system_id cable_dmi_table[] = {
{
.ident = "HP Pavilion N5430",
.matches = {
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/pata_cs5530.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ static struct ata_port_operations cs5530_port_ops = {
.port_start = ata_port_start,
};

static struct dmi_system_id palmax_dmi_table[] = {
static const struct dmi_system_id palmax_dmi_table[] = {
{
.ident = "Palmax PD1100",
.matches = {
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/pata_via.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static const struct via_isa_bridge {
* Cable special cases
*/

static struct dmi_system_id cable_dmi_table[] = {
static const struct dmi_system_id cable_dmi_table[] = {
{
.ident = "Acer Ferrari 3400",
.matches = {
Expand Down
4 changes: 2 additions & 2 deletions drivers/char/i8k.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ struct smm_regs {
unsigned int edi __attribute__ ((packed));
};

static inline char *i8k_get_dmi_data(int field)
static inline const char *i8k_get_dmi_data(int field)
{
char *dmi_data = dmi_get_system_info(field);
const char *dmi_data = dmi_get_system_info(field);

return dmi_data && *dmi_data ? dmi_data : "?";
}
Expand Down
9 changes: 5 additions & 4 deletions drivers/char/ipmi/ipmi_si_intf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1965,10 +1965,10 @@ struct dmi_ipmi_data
u8 slave_addr;
};

static int __devinit decode_dmi(struct dmi_header *dm,
static int __devinit decode_dmi(const struct dmi_header *dm,
struct dmi_ipmi_data *dmi)
{
u8 *data = (u8 *)dm;
const u8 *data = (const u8 *)dm;
unsigned long base_addr;
u8 reg_spacing;
u8 len = dm->length;
Expand Down Expand Up @@ -2091,13 +2091,14 @@ static __devinit void try_init_dmi(struct dmi_ipmi_data *ipmi_data)

static void __devinit dmi_find_bmc(void)
{
struct dmi_device *dev = NULL;
const struct dmi_device *dev = NULL;
struct dmi_ipmi_data data;
int rv;

while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev))) {
memset(&data, 0, sizeof(data));
rv = decode_dmi((struct dmi_header *) dev->device_data, &data);
rv = decode_dmi((const struct dmi_header *) dev->device_data,
&data);
if (!rv)
try_init_dmi(&data);
}
Expand Down
Loading

0 comments on commit 1855256

Please sign in to comment.