Skip to content

Commit e51cd9c

Browse files
Keith Buschbjorn-helgaas
authored andcommitted
PCI/AER: Refactor error injection fallbacks
Move the bus ops fallback into separate functions. No functional change here. Signed-off-by: Keith Busch <keith.busch@intel.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent 390e2db commit e51cd9c

File tree

1 file changed

+38
-28
lines changed

1 file changed

+38
-28
lines changed

drivers/pci/pcie/aer_inject.c

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,48 @@ static u32 *find_pci_config_dword(struct aer_error *err, int where,
176176
return target;
177177
}
178178

179+
static int aer_inj_read(struct pci_bus *bus, unsigned int devfn, int where,
180+
int size, u32 *val)
181+
{
182+
struct pci_ops *ops, *my_ops;
183+
int rv;
184+
185+
ops = __find_pci_bus_ops(bus);
186+
if (!ops)
187+
return -1;
188+
189+
my_ops = bus->ops;
190+
bus->ops = ops;
191+
rv = ops->read(bus, devfn, where, size, val);
192+
bus->ops = my_ops;
193+
194+
return rv;
195+
}
196+
197+
static int aer_inj_write(struct pci_bus *bus, unsigned int devfn, int where,
198+
int size, u32 val)
199+
{
200+
struct pci_ops *ops, *my_ops;
201+
int rv;
202+
203+
ops = __find_pci_bus_ops(bus);
204+
if (!ops)
205+
return -1;
206+
207+
my_ops = bus->ops;
208+
bus->ops = ops;
209+
rv = ops->write(bus, devfn, where, size, val);
210+
bus->ops = my_ops;
211+
212+
return rv;
213+
}
214+
179215
static int aer_inj_read_config(struct pci_bus *bus, unsigned int devfn,
180216
int where, int size, u32 *val)
181217
{
182218
u32 *sim;
183219
struct aer_error *err;
184220
unsigned long flags;
185-
struct pci_ops *ops;
186-
struct pci_ops *my_ops;
187221
int domain;
188222
int rv;
189223

@@ -204,18 +238,7 @@ static int aer_inj_read_config(struct pci_bus *bus, unsigned int devfn,
204238
return 0;
205239
}
206240
out:
207-
ops = __find_pci_bus_ops(bus);
208-
/*
209-
* pci_lock must already be held, so we can directly
210-
* manipulate bus->ops. Many config access functions,
211-
* including pci_generic_config_read() require the original
212-
* bus->ops be installed to function, so temporarily put them
213-
* back.
214-
*/
215-
my_ops = bus->ops;
216-
bus->ops = ops;
217-
rv = ops->read(bus, devfn, where, size, val);
218-
bus->ops = my_ops;
241+
rv = aer_inj_read(bus, devfn, where, size, val);
219242
spin_unlock_irqrestore(&inject_lock, flags);
220243
return rv;
221244
}
@@ -227,8 +250,6 @@ static int aer_inj_write_config(struct pci_bus *bus, unsigned int devfn,
227250
struct aer_error *err;
228251
unsigned long flags;
229252
int rw1cs;
230-
struct pci_ops *ops;
231-
struct pci_ops *my_ops;
232253
int domain;
233254
int rv;
234255

@@ -252,18 +273,7 @@ static int aer_inj_write_config(struct pci_bus *bus, unsigned int devfn,
252273
return 0;
253274
}
254275
out:
255-
ops = __find_pci_bus_ops(bus);
256-
/*
257-
* pci_lock must already be held, so we can directly
258-
* manipulate bus->ops. Many config access functions,
259-
* including pci_generic_config_write() require the original
260-
* bus->ops be installed to function, so temporarily put them
261-
* back.
262-
*/
263-
my_ops = bus->ops;
264-
bus->ops = ops;
265-
rv = ops->write(bus, devfn, where, size, val);
266-
bus->ops = my_ops;
276+
rv = aer_inj_write(bus, devfn, where, size, val);
267277
spin_unlock_irqrestore(&inject_lock, flags);
268278
return rv;
269279
}

0 commit comments

Comments
 (0)