/* * Copyright (C) 2003-2008 Takahiro Hirofuchi * Copyright (C) 2015 Nobuo Iwata * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * */ #ifndef __USBIP_VHCI_H #define __USBIP_VHCI_H #include #include #include #include #include #include #include #include struct vhci_device { struct usb_device *udev; /* * devid specifies a remote usb device uniquely instead * of combination of busnum and devnum. */ __u32 devid; /* speed of a remote device */ enum usb_device_speed speed; /* vhci root-hub port to which this device is attached */ __u32 rhport; struct usbip_device ud; /* lock for the below link lists */ spinlock_t priv_lock; /* vhci_priv is linked to one of them. */ struct list_head priv_tx; struct list_head priv_rx; /* vhci_unlink is linked to one of them */ struct list_head unlink_tx; struct list_head unlink_rx; /* vhci_tx thread sleeps for this queue */ wait_queue_head_t waitq_tx; }; /* urb->hcpriv, use container_of() */ struct vhci_priv { unsigned long seqnum; struct list_head list; struct vhci_device *vdev; struct urb *urb; }; struct vhci_unlink { /* seqnum of this request */ unsigned long seqnum; struct list_head list; /* seqnum of the unlink target */ unsigned long unlink_seqnum; }; /* Number of supported ports. Value has an upperbound of USB_MAXCHILDREN */ #ifdef CONFIG_USBIP_VHCI_HC_PORTS #define VHCI_HC_PORTS CONFIG_USBIP_VHCI_HC_PORTS #else #define VHCI_HC_PORTS 8 #endif #ifdef CONFIG_USBIP_VHCI_NR_HCS #define VHCI_NR_HCS CONFIG_USBIP_VHCI_NR_HCS #else #define VHCI_NR_HCS 1 #endif #define MAX_STATUS_NAME 16 /* for usb_bus.hcpriv */ struct vhci_hcd { spinlock_t lock; u32 port_status[VHCI_HC_PORTS]; unsigned resuming:1; unsigned long re_timeout; atomic_t seqnum; /* * NOTE: * wIndex shows the port number and begins from 1. * But, the index of this array begins from 0. */ struct vhci_device vdev[VHCI_HC_PORTS]; }; extern int vhci_num_controllers; extern struct platform_device **vhci_pdevs; extern struct attribute_group vhci_attr_group; /* vhci_hcd.c */ void rh_port_connect(struct vhci_device *vdev, enum usb_device_speed speed); /* vhci_sysfs.c */ int vhci_init_attr_group(void); void vhci_finish_attr_group(void); /* vhci_rx.c */ struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum); int vhci_rx_loop(void *data); /* vhci_tx.c */ int vhci_tx_loop(void *data); static inline __u32 port_to_rhport(__u32 port) { return port % VHCI_HC_PORTS; } static inline int port_to_pdev_nr(__u32 port) { return port / VHCI_HC_PORTS; } static inline struct vhci_hcd *hcd_to_vhci(struct usb_hcd *hcd) { return (struct vhci_hcd *) (hcd->hcd_priv); } static inline struct device *hcd_dev(struct usb_hcd *hcd) { return (hcd)->self.controller; } static inline const char *hcd_name(struct usb_hcd *hcd) { return (hcd)->self.bus_name; } static inline struct usb_hcd *vhci_to_hcd(struct vhci_hcd *vhci) { return container_of((void *) vhci, struct usb_hcd, hcd_priv); } static inline struct vhci_hcd *vdev_to_vhci(struct vhci_device *vdev) { return container_of( (void *)(vdev - vdev->rhport), struct vhci_hcd, vdev); } #endif /* __USBIP_VHCI_H */ .git/commit/sound/soc/codecs/adau1977-i2c.c?h=nds-private-remove&id=91539eb1fda2d530d3b268eef542c5414e54bf1a'>adau1977-i2c.c
diff options
context:
space:
mode:
authorIago Abal <mail@iagoabal.eu>2017-01-11 14:00:21 +0100
committerVinod Koul <vinod.koul@intel.com>2017-01-25 15:35:11 +0530
commit91539eb1fda2d530d3b268eef542c5414e54bf1a (patch)
tree960f5ca6342ad20837aff18aad6e8ecd7da32fd6 /sound/soc/codecs/adau1977-i2c.c
parent6610d0edf6dc7ee97e46ab3a538a565c79d26199 (diff)
dmaengine: pl330: fix double lock
The static bug finder EBA (http://www.iagoabal.eu/eba/) reported the following double-lock bug: Double lock: 1. spin_lock_irqsave(pch->lock, flags) at pl330_free_chan_resources:2236; 2. call to function `pl330_release_channel' immediately after; 3. call to function `dma_pl330_rqcb' in line 1753; 4. spin_lock_irqsave(pch->lock, flags) at dma_pl330_rqcb:1505. I have fixed it as suggested by Marek Szyprowski. First, I have replaced `pch->lock' with `pl330->lock' in functions `pl330_alloc_chan_resources' and `pl330_free_chan_resources'. This avoids the double-lock by acquiring a different lock than `dma_pl330_rqcb'. NOTE that, as a result, `pl330_free_chan_resources' executes `list_splice_tail_init' on `pch->work_list' under lock `pl330->lock', whereas in the rest of the code `pch->work_list' is protected by `pch->lock'. I don't know if this may cause race conditions. Similarly `pch->cyclic' is written by `pl330_alloc_chan_resources' under `pl330->lock' but read by `pl330_tx_submit' under `pch->lock'. Second, I have removed locking from `pl330_request_channel' and `pl330_release_channel' functions. Function `pl330_request_channel' is only called from `pl330_alloc_chan_resources', so the lock is already held. Function `pl330_release_channel' is called from `pl330_free_chan_resources', which already holds the lock, and from `pl330_del'. Function `pl330_del' is called in an error path of `pl330_probe' and at the end of `pl330_remove', but I assume that there cannot be concurrent accesses to the protected data at those points. Signed-off-by: Iago Abal <mail@iagoabal.eu> Reviewed-by: Marek Szyprowski <m.szyprowski@samsung.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Diffstat (limited to 'sound/soc/codecs/adau1977-i2c.c')