Skip to content

Commit 19f516e

Browse files
committed
Merge tag 'for-linus' of git://git.armlinux.org.uk/~rmk/linux-arm
Pull ARM fix from Russell King: "Just one fix for now for the AMBA bus code from Isaac Manjarres" * tag 'for-linus' of git://git.armlinux.org.uk/~rmk/linux-arm: ARM: 9229/1: amba: Fix use-after-free in amba_read_periphid()
2 parents d2ec799 + 25af740 commit 19f516e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

drivers/amba/bus.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ static int amba_match(struct device *dev, struct device_driver *drv)
209209
struct amba_device *pcdev = to_amba_device(dev);
210210
struct amba_driver *pcdrv = to_amba_driver(drv);
211211

212+
mutex_lock(&pcdev->periphid_lock);
212213
if (!pcdev->periphid) {
213214
int ret = amba_read_periphid(pcdev);
214215

@@ -218,11 +219,14 @@ static int amba_match(struct device *dev, struct device_driver *drv)
218219
* permanent failure in reading pid and cid, simply map it to
219220
* -EPROBE_DEFER.
220221
*/
221-
if (ret)
222+
if (ret) {
223+
mutex_unlock(&pcdev->periphid_lock);
222224
return -EPROBE_DEFER;
225+
}
223226
dev_set_uevent_suppress(dev, false);
224227
kobject_uevent(&dev->kobj, KOBJ_ADD);
225228
}
229+
mutex_unlock(&pcdev->periphid_lock);
226230

227231
/* When driver_override is set, only bind to the matching driver */
228232
if (pcdev->driver_override)
@@ -532,6 +536,7 @@ static void amba_device_release(struct device *dev)
532536

533537
if (d->res.parent)
534538
release_resource(&d->res);
539+
mutex_destroy(&d->periphid_lock);
535540
kfree(d);
536541
}
537542

@@ -584,6 +589,7 @@ static void amba_device_initialize(struct amba_device *dev, const char *name)
584589
dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
585590
dev->dev.dma_parms = &dev->dma_parms;
586591
dev->res.name = dev_name(&dev->dev);
592+
mutex_init(&dev->periphid_lock);
587593
}
588594

589595
/**

include/linux/amba/bus.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct amba_device {
6767
struct clk *pclk;
6868
struct device_dma_parameters dma_parms;
6969
unsigned int periphid;
70+
struct mutex periphid_lock;
7071
unsigned int cid;
7172
struct amba_cs_uci_id uci;
7273
unsigned int irq[AMBA_NR_IRQS];

0 commit comments

Comments
 (0)