Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mfd: intel_quark_i2c_gpio: Don't crash if !DMI

dmi_get_system_info() may return NULL either when CONFIG_DMI is not set or when
board has an old firmware. The patch prevents a crash and changes the default
frequency to be in align with older board.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
[Lee: Removed overt "sentinel" comment and extra lines]
Signed-off-by: Lee Jones <lee.jones@linaro.org>

authored by

Andy Shevchenko and committed by
Lee Jones
bafc1fac 0787ded8

+12 -7
+12 -7
drivers/mfd/intel_quark_i2c_gpio.c
··· 70 70 .name = "GalileoGen2", 71 71 .i2c_scl_freq = 400000, 72 72 }, 73 + {} 73 74 }; 74 75 75 76 static struct resource intel_quark_i2c_res[] = { ··· 154 153 static int intel_quark_i2c_setup(struct pci_dev *pdev, struct mfd_cell *cell) 155 154 { 156 155 const char *board_name = dmi_get_system_info(DMI_BOARD_NAME); 156 + const struct i2c_mode_info *info; 157 157 struct dw_i2c_platform_data *pdata; 158 158 struct resource *res = (struct resource *)cell->resources; 159 159 struct device *dev = &pdev->dev; 160 - unsigned int i; 161 160 162 161 res[INTEL_QUARK_IORES_MEM].start = 163 162 pci_resource_start(pdev, MFD_I2C_BAR); ··· 171 170 if (!pdata) 172 171 return -ENOMEM; 173 172 174 - /* Fast mode by default */ 175 - pdata->i2c_scl_freq = 400000; 173 + /* Normal mode by default */ 174 + pdata->i2c_scl_freq = 100000; 176 175 177 - for (i = 0; i < ARRAY_SIZE(platform_i2c_mode_info); i++) 178 - if (!strcmp(board_name, platform_i2c_mode_info[i].name)) 179 - pdata->i2c_scl_freq 180 - = platform_i2c_mode_info[i].i2c_scl_freq; 176 + if (board_name) { 177 + for (info = platform_i2c_mode_info; info->name; info++) { 178 + if (!strcmp(board_name, info->name)) { 179 + pdata->i2c_scl_freq = info->i2c_scl_freq; 180 + break; 181 + } 182 + } 183 + } 181 184 182 185 cell->platform_data = pdata; 183 186 cell->pdata_size = sizeof(*pdata);