Skip to content

Commit 9244524

Browse files
kawasakiij-intel
authored andcommitted
p2sb: Factor out p2sb_read_from_cache()
To prepare for the following fix, factor out the code to read the P2SB resource from the cache to the new function p2sb_read_from_cache(). Signed-off-by: Shin'ichiro Kawasaki <[email protected]> Reviewed-by: Hans de Goede <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]>
1 parent 54a8cad commit 9244524

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

drivers/platform/x86/p2sb.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,22 @@ static int p2sb_cache_resources(void)
172172
return ret;
173173
}
174174

175+
static int p2sb_read_from_cache(struct pci_bus *bus, unsigned int devfn,
176+
struct resource *mem)
177+
{
178+
struct p2sb_res_cache *cache = &p2sb_resources[PCI_FUNC(devfn)];
179+
180+
if (cache->bus_dev_id != bus->dev.id)
181+
return -ENODEV;
182+
183+
if (!p2sb_valid_resource(&cache->res))
184+
return -ENOENT;
185+
186+
memcpy(mem, &cache->res, sizeof(*mem));
187+
188+
return 0;
189+
}
190+
175191
/**
176192
* p2sb_bar - Get Primary to Sideband (P2SB) bridge device BAR
177193
* @bus: PCI bus to communicate with
@@ -188,24 +204,14 @@ static int p2sb_cache_resources(void)
188204
*/
189205
int p2sb_bar(struct pci_bus *bus, unsigned int devfn, struct resource *mem)
190206
{
191-
struct p2sb_res_cache *cache;
192-
193207
bus = p2sb_get_bus(bus);
194208
if (!bus)
195209
return -ENODEV;
196210

197211
if (!devfn)
198212
p2sb_get_devfn(&devfn);
199213

200-
cache = &p2sb_resources[PCI_FUNC(devfn)];
201-
if (cache->bus_dev_id != bus->dev.id)
202-
return -ENODEV;
203-
204-
if (!p2sb_valid_resource(&cache->res))
205-
return -ENOENT;
206-
207-
memcpy(mem, &cache->res, sizeof(*mem));
208-
return 0;
214+
return p2sb_read_from_cache(bus, devfn, mem);
209215
}
210216
EXPORT_SYMBOL_GPL(p2sb_bar);
211217

0 commit comments

Comments
 (0)