Add patches accepted for 2.6.27-rc1
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / releases / upstream / 2.6.27-rc1 / 0007-ACPI-thinkpad-acpi-don-t-misdetect-in-get_thinkpad.patch
blob81aa88b14ecc61cb9ecbc91bb2ef124da2da0a65
1 From bf20e740a4bcc686de02e2fd1c1810a58872f46e Mon Sep 17 00:00:00 2001
2 From: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
3 Date: Mon, 21 Jul 2008 09:15:51 -0300
4 Subject: ACPI: thinkpad-acpi: don't misdetect in get_thinkpad_model_data() on -ENOMEM
6 Explicitly check for memory allocation failures, and return status to
7 indicate that we could not collect data due to errors.
9 This lets the driver have a far more predictable failure mode on ENOMEM in
10 that codepath: it will refuse to load. This is far better than trying to
11 proceed with missing data which is used to detect quirks, etc.
13 Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
14 ---
15 drivers/misc/thinkpad_acpi.c | 47 +++++++++++++++++++++++++++++------------
16 1 files changed, 33 insertions(+), 14 deletions(-)
18 diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c
19 index 3eb01af..d3eb790 100644
20 --- a/drivers/misc/thinkpad_acpi.c
21 +++ b/drivers/misc/thinkpad_acpi.c
22 @@ -6340,13 +6340,18 @@ err_out:
24 /* Probing */
26 -static void __init get_thinkpad_model_data(struct thinkpad_id_data *tp)
27 +/* returns 0 - probe ok, or < 0 - probe error.
28 + * Probe ok doesn't mean thinkpad found.
29 + * On error, kfree() cleanup on tp->* is not performed, caller must do it */
30 +static int __must_check __init get_thinkpad_model_data(
31 + struct thinkpad_id_data *tp)
33 const struct dmi_device *dev = NULL;
34 char ec_fw_string[18];
35 + char const *s;
37 if (!tp)
38 - return;
39 + return -EINVAL;
41 memset(tp, 0, sizeof(*tp));
43 @@ -6355,12 +6360,14 @@ static void __init get_thinkpad_model_data(struct thinkpad_id_data *tp)
44 else if (dmi_name_in_vendors("LENOVO"))
45 tp->vendor = PCI_VENDOR_ID_LENOVO;
46 else
47 - return;
48 + return 0;
50 - tp->bios_version_str = kstrdup(dmi_get_system_info(DMI_BIOS_VERSION),
51 - GFP_KERNEL);
52 + s = dmi_get_system_info(DMI_BIOS_VERSION);
53 + tp->bios_version_str = kstrdup(s, GFP_KERNEL);
54 + if (s && !tp->bios_version_str)
55 + return -ENOMEM;
56 if (!tp->bios_version_str)
57 - return;
58 + return 0;
59 tp->bios_model = tp->bios_version_str[0]
60 | (tp->bios_version_str[1] << 8);
62 @@ -6379,21 +6386,27 @@ static void __init get_thinkpad_model_data(struct thinkpad_id_data *tp)
63 ec_fw_string[strcspn(ec_fw_string, " ]")] = 0;
65 tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL);
66 + if (!tp->ec_version_str)
67 + return -ENOMEM;
68 tp->ec_model = ec_fw_string[0]
69 | (ec_fw_string[1] << 8);
70 break;
74 - tp->model_str = kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION),
75 - GFP_KERNEL);
76 - if (tp->model_str && strnicmp(tp->model_str, "ThinkPad", 8) != 0) {
77 - kfree(tp->model_str);
78 - tp->model_str = NULL;
79 + s = dmi_get_system_info(DMI_PRODUCT_VERSION);
80 + if (s && !strnicmp(s, "ThinkPad", 8)) {
81 + tp->model_str = kstrdup(s, GFP_KERNEL);
82 + if (!tp->model_str)
83 + return -ENOMEM;
86 - tp->nummodel_str = kstrdup(dmi_get_system_info(DMI_PRODUCT_NAME),
87 - GFP_KERNEL);
88 + s = dmi_get_system_info(DMI_PRODUCT_NAME);
89 + tp->nummodel_str = kstrdup(s, GFP_KERNEL);
90 + if (s && !tp->nummodel_str)
91 + return -ENOMEM;
93 + return 0;
96 static int __init probe_for_thinkpad(void)
97 @@ -6656,7 +6669,13 @@ static int __init thinkpad_acpi_module_init(void)
99 /* Driver-level probe */
101 - get_thinkpad_model_data(&thinkpad_id);
102 + ret = get_thinkpad_model_data(&thinkpad_id);
103 + if (ret) {
104 + printk(TPACPI_ERR
105 + "unable to get DMI data: %d\n", ret);
106 + thinkpad_acpi_module_exit();
107 + return ret;
109 ret = probe_for_thinkpad();
110 if (ret) {
111 thinkpad_acpi_module_exit();
113 1.5.6.2