Skip to content

Commit 4f30713

Browse files
andy-shevmchehab
authored andcommitted
media: atomisp: Use proper APIs to find I²C client device by ACPI HID
There are specific ACPI and I\xB2C APIs to match device by different parameters, such as ACPI HID, and retrieve an I\xB2C client. Use them instead of home grown approach. Note, it fixes a resource leak as well. Signed-off-by: Andy Shevchenko <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 5f55dd5 commit 4f30713

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ struct gmin_subdev {
9696
static struct gmin_subdev gmin_subdevs[MAX_SUBDEVS];
9797

9898
/* ACPI HIDs for the PMICs that could be used by this driver */
99-
#define PMIC_ACPI_AXP "INT33F4:00" /* XPower AXP288 PMIC */
100-
#define PMIC_ACPI_TI "INT33F5:00" /* Dollar Cove TI PMIC */
101-
#define PMIC_ACPI_CRYSTALCOVE "INT33FD:00" /* Crystal Cove PMIC */
99+
#define PMIC_ACPI_AXP "INT33F4" /* XPower AXP288 PMIC */
100+
#define PMIC_ACPI_TI "INT33F5" /* Dollar Cove TI PMIC */
101+
#define PMIC_ACPI_CRYSTALCOVE "INT33FD" /* Crystal Cove PMIC */
102102

103103
#define PMIC_PLATFORM_TI "intel_soc_pmic_chtdc_ti"
104104

@@ -371,34 +371,27 @@ static const guid_t atomisp_dsm_guid = GUID_INIT(0xdc2f6c4f, 0x045b, 0x4f1d,
371371
#define GMIN_PMC_CLK_NAME 14 /* "pmc_plt_clk_[0..5]" */
372372
static char gmin_pmc_clk_name[GMIN_PMC_CLK_NAME];
373373

374-
static int gmin_i2c_match_one(struct device *dev, const void *data)
375-
{
376-
const char *name = data;
377-
struct i2c_client *client;
378-
379-
if (dev->type != &i2c_client_type)
380-
return 0;
381-
382-
client = to_i2c_client(dev);
383-
384-
return (!strcmp(name, client->name));
385-
}
386-
387374
static struct i2c_client *gmin_i2c_dev_exists(struct device *dev, char *name,
388375
struct i2c_client **client)
389376
{
377+
struct acpi_device *adev;
390378
struct device *d;
391379

392-
while ((d = bus_find_device(&i2c_bus_type, NULL, name,
393-
gmin_i2c_match_one))) {
394-
*client = to_i2c_client(d);
395-
dev_dbg(dev, "found '%s' at address 0x%02x, adapter %d\n",
396-
(*client)->name, (*client)->addr,
397-
(*client)->adapter->nr);
398-
return *client;
399-
}
380+
adev = acpi_dev_get_first_match_dev(name, NULL, -1);
381+
if (!adev)
382+
return NULL;
400383

401-
return NULL;
384+
d = bus_find_device_by_acpi_dev(&i2c_bus_type, adev);
385+
acpi_dev_put(adev);
386+
if (!d)
387+
return NULL;
388+
389+
*client = i2c_verify_client(d);
390+
put_device(d);
391+
392+
dev_dbg(dev, "found '%s' at address 0x%02x, adapter %d\n",
393+
(*client)->name, (*client)->addr, (*client)->adapter->nr);
394+
return *client;
402395
}
403396

404397
static int gmin_i2c_write(struct device *dev, u16 i2c_addr, u8 reg,

0 commit comments

Comments
 (0)