Commit bec09bce authored by Alistair Strachan's avatar Alistair Strachan Committed by Greg Kroah-Hartman

staging: Android: asoc: Fix sparse warnings in vsoc driver.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Arve Hjønnevåg <arve@android.com>
Cc: Todd Kjos <tkjos@android.com>
Cc: Martijn Coenen <maco@android.com>
Cc: Greg Hartman <ghartman@google.com>
Cc: devel@driverdev.osuosl.org
Cc: kernel-team@android.com
Signed-off-by: default avatarAlistair Strachan <astrachan@google.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent dc5b1133
...@@ -81,8 +81,8 @@ struct vsoc_region_data { ...@@ -81,8 +81,8 @@ struct vsoc_region_data {
atomic_t *incoming_signalled; atomic_t *incoming_signalled;
/* Flag indicating the guest has signalled the host. */ /* Flag indicating the guest has signalled the host. */
atomic_t *outgoing_signalled; atomic_t *outgoing_signalled;
int irq_requested; bool irq_requested;
int device_created; bool device_created;
}; };
struct vsoc_device { struct vsoc_device {
...@@ -91,7 +91,7 @@ struct vsoc_device { ...@@ -91,7 +91,7 @@ struct vsoc_device {
/* Physical address of SHARED_MEMORY_BAR. */ /* Physical address of SHARED_MEMORY_BAR. */
phys_addr_t shm_phys_start; phys_addr_t shm_phys_start;
/* Kernel virtual address of SHARED_MEMORY_BAR. */ /* Kernel virtual address of SHARED_MEMORY_BAR. */
void *kernel_mapped_shm; void __iomem *kernel_mapped_shm;
/* Size of the entire shared memory window in bytes. */ /* Size of the entire shared memory window in bytes. */
size_t shm_size; size_t shm_size;
/* /*
...@@ -116,22 +116,23 @@ struct vsoc_device { ...@@ -116,22 +116,23 @@ struct vsoc_device {
* vsoc_region_data because the kernel deals with them as an array. * vsoc_region_data because the kernel deals with them as an array.
*/ */
struct msix_entry *msix_entries; struct msix_entry *msix_entries;
/*
* Flags that indicate what we've initialzied. These are used to do an
* orderly cleanup of the device.
*/
char enabled_device;
char requested_regions;
char cdev_added;
char class_added;
char msix_enabled;
/* Mutex that protectes the permission list */ /* Mutex that protectes the permission list */
struct mutex mtx; struct mutex mtx;
/* Major number assigned by the kernel */ /* Major number assigned by the kernel */
int major; int major;
/* Character device assigned by the kernel */
struct cdev cdev; struct cdev cdev;
/* Device class assigned by the kernel */
struct class *class; struct class *class;
/*
* Flags that indicate what we've initialized. These are used to do an
* orderly cleanup of the device.
*/
bool enabled_device;
bool requested_regions;
bool cdev_added;
bool class_added;
bool msix_enabled;
}; };
static struct vsoc_device vsoc_dev; static struct vsoc_device vsoc_dev;
...@@ -153,13 +154,13 @@ static long vsoc_ioctl(struct file *, unsigned int, unsigned long); ...@@ -153,13 +154,13 @@ static long vsoc_ioctl(struct file *, unsigned int, unsigned long);
static int vsoc_mmap(struct file *, struct vm_area_struct *); static int vsoc_mmap(struct file *, struct vm_area_struct *);
static int vsoc_open(struct inode *, struct file *); static int vsoc_open(struct inode *, struct file *);
static int vsoc_release(struct inode *, struct file *); static int vsoc_release(struct inode *, struct file *);
static ssize_t vsoc_read(struct file *, char *, size_t, loff_t *); static ssize_t vsoc_read(struct file *, char __user *, size_t, loff_t *);
static ssize_t vsoc_write(struct file *, const char *, size_t, loff_t *); static ssize_t vsoc_write(struct file *, const char __user *, size_t, loff_t *);
static loff_t vsoc_lseek(struct file *filp, loff_t offset, int origin); static loff_t vsoc_lseek(struct file *filp, loff_t offset, int origin);
static int do_create_fd_scoped_permission( static int do_create_fd_scoped_permission(
struct vsoc_device_region *region_p, struct vsoc_device_region *region_p,
struct fd_scoped_permission_node *np, struct fd_scoped_permission_node *np,
struct fd_scoped_permission_arg *__user arg); struct fd_scoped_permission_arg __user *arg);
static void do_destroy_fd_scoped_permission( static void do_destroy_fd_scoped_permission(
struct vsoc_device_region *owner_region_p, struct vsoc_device_region *owner_region_p,
struct fd_scoped_permission *perm); struct fd_scoped_permission *perm);
...@@ -198,7 +199,7 @@ inline int vsoc_validate_filep(struct file *filp) ...@@ -198,7 +199,7 @@ inline int vsoc_validate_filep(struct file *filp)
/* Converts from shared memory offset to virtual address */ /* Converts from shared memory offset to virtual address */
static inline void *shm_off_to_virtual_addr(__u32 offset) static inline void *shm_off_to_virtual_addr(__u32 offset)
{ {
return vsoc_dev.kernel_mapped_shm + offset; return (void __force *)vsoc_dev.kernel_mapped_shm + offset;
} }
/* Converts from shared memory offset to physical address */ /* Converts from shared memory offset to physical address */
...@@ -261,7 +262,7 @@ static struct pci_driver vsoc_pci_driver = { ...@@ -261,7 +262,7 @@ static struct pci_driver vsoc_pci_driver = {
static int do_create_fd_scoped_permission( static int do_create_fd_scoped_permission(
struct vsoc_device_region *region_p, struct vsoc_device_region *region_p,
struct fd_scoped_permission_node *np, struct fd_scoped_permission_node *np,
struct fd_scoped_permission_arg *__user arg) struct fd_scoped_permission_arg __user *arg)
{ {
struct file *managed_filp; struct file *managed_filp;
s32 managed_fd; s32 managed_fd;
...@@ -632,11 +633,11 @@ static long vsoc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -632,11 +633,11 @@ static long vsoc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
return 0; return 0;
} }
static ssize_t vsoc_read(struct file *filp, char *buffer, size_t len, static ssize_t vsoc_read(struct file *filp, char __user *buffer, size_t len,
loff_t *poffset) loff_t *poffset)
{ {
__u32 area_off; __u32 area_off;
void *area_p; const void *area_p;
ssize_t area_len; ssize_t area_len;
int retval = vsoc_validate_filep(filp); int retval = vsoc_validate_filep(filp);
...@@ -706,7 +707,7 @@ static loff_t vsoc_lseek(struct file *filp, loff_t offset, int origin) ...@@ -706,7 +707,7 @@ static loff_t vsoc_lseek(struct file *filp, loff_t offset, int origin)
return offset; return offset;
} }
static ssize_t vsoc_write(struct file *filp, const char *buffer, static ssize_t vsoc_write(struct file *filp, const char __user *buffer,
size_t len, loff_t *poffset) size_t len, loff_t *poffset)
{ {
__u32 area_off; __u32 area_off;
...@@ -772,14 +773,14 @@ static int vsoc_probe_device(struct pci_dev *pdev, ...@@ -772,14 +773,14 @@ static int vsoc_probe_device(struct pci_dev *pdev,
pci_name(pdev), result); pci_name(pdev), result);
return result; return result;
} }
vsoc_dev.enabled_device = 1; vsoc_dev.enabled_device = true;
result = pci_request_regions(pdev, "vsoc"); result = pci_request_regions(pdev, "vsoc");
if (result < 0) { if (result < 0) {
dev_err(&pdev->dev, "pci_request_regions failed\n"); dev_err(&pdev->dev, "pci_request_regions failed\n");
vsoc_remove_device(pdev); vsoc_remove_device(pdev);
return -EBUSY; return -EBUSY;
} }
vsoc_dev.requested_regions = 1; vsoc_dev.requested_regions = true;
/* Set up the control registers in BAR 0 */ /* Set up the control registers in BAR 0 */
reg_size = pci_resource_len(pdev, REGISTER_BAR); reg_size = pci_resource_len(pdev, REGISTER_BAR);
if (reg_size > MAX_REGISTER_BAR_LEN) if (reg_size > MAX_REGISTER_BAR_LEN)
...@@ -790,7 +791,7 @@ static int vsoc_probe_device(struct pci_dev *pdev, ...@@ -790,7 +791,7 @@ static int vsoc_probe_device(struct pci_dev *pdev,
if (!vsoc_dev.regs) { if (!vsoc_dev.regs) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
"cannot ioremap registers of size %zu\n", "cannot map registers of size %zu\n",
(size_t)reg_size); (size_t)reg_size);
vsoc_remove_device(pdev); vsoc_remove_device(pdev);
return -EBUSY; return -EBUSY;
...@@ -809,8 +810,8 @@ static int vsoc_probe_device(struct pci_dev *pdev, ...@@ -809,8 +810,8 @@ static int vsoc_probe_device(struct pci_dev *pdev,
return -EBUSY; return -EBUSY;
} }
vsoc_dev.layout = vsoc_dev.layout = (struct vsoc_shm_layout_descriptor __force *)
(struct vsoc_shm_layout_descriptor *)vsoc_dev.kernel_mapped_shm; vsoc_dev.kernel_mapped_shm;
dev_info(&pdev->dev, "major_version: %d\n", dev_info(&pdev->dev, "major_version: %d\n",
vsoc_dev.layout->major_version); vsoc_dev.layout->major_version);
dev_info(&pdev->dev, "minor_version: %d\n", dev_info(&pdev->dev, "minor_version: %d\n",
...@@ -841,16 +842,16 @@ static int vsoc_probe_device(struct pci_dev *pdev, ...@@ -841,16 +842,16 @@ static int vsoc_probe_device(struct pci_dev *pdev,
vsoc_remove_device(pdev); vsoc_remove_device(pdev);
return -EBUSY; return -EBUSY;
} }
vsoc_dev.cdev_added = 1; vsoc_dev.cdev_added = true;
vsoc_dev.class = class_create(THIS_MODULE, VSOC_DEV_NAME); vsoc_dev.class = class_create(THIS_MODULE, VSOC_DEV_NAME);
if (IS_ERR(vsoc_dev.class)) { if (IS_ERR(vsoc_dev.class)) {
dev_err(&vsoc_dev.dev->dev, "class_create failed\n"); dev_err(&vsoc_dev.dev->dev, "class_create failed\n");
vsoc_remove_device(pdev); vsoc_remove_device(pdev);
return PTR_ERR(vsoc_dev.class); return PTR_ERR(vsoc_dev.class);
} }
vsoc_dev.class_added = 1; vsoc_dev.class_added = true;
vsoc_dev.regions = (struct vsoc_device_region *) vsoc_dev.regions = (struct vsoc_device_region __force *)
(vsoc_dev.kernel_mapped_shm + ((void *)vsoc_dev.layout +
vsoc_dev.layout->vsoc_region_desc_offset); vsoc_dev.layout->vsoc_region_desc_offset);
vsoc_dev.msix_entries = kcalloc( vsoc_dev.msix_entries = kcalloc(
vsoc_dev.layout->region_count, vsoc_dev.layout->region_count,
...@@ -910,7 +911,7 @@ static int vsoc_probe_device(struct pci_dev *pdev, ...@@ -910,7 +911,7 @@ static int vsoc_probe_device(struct pci_dev *pdev,
return -EFAULT; return -EFAULT;
} }
} }
vsoc_dev.msix_enabled = 1; vsoc_dev.msix_enabled = true;
for (i = 0; i < vsoc_dev.layout->region_count; ++i) { for (i = 0; i < vsoc_dev.layout->region_count; ++i) {
const struct vsoc_device_region *region = vsoc_dev.regions + i; const struct vsoc_device_region *region = vsoc_dev.regions + i;
size_t name_sz = sizeof(vsoc_dev.regions_data[i].name) - 1; size_t name_sz = sizeof(vsoc_dev.regions_data[i].name) - 1;
...@@ -928,14 +929,11 @@ static int vsoc_probe_device(struct pci_dev *pdev, ...@@ -928,14 +929,11 @@ static int vsoc_probe_device(struct pci_dev *pdev,
&vsoc_dev.regions_data[i].interrupt_wait_queue); &vsoc_dev.regions_data[i].interrupt_wait_queue);
init_waitqueue_head(&vsoc_dev.regions_data[i].futex_wait_queue); init_waitqueue_head(&vsoc_dev.regions_data[i].futex_wait_queue);
vsoc_dev.regions_data[i].incoming_signalled = vsoc_dev.regions_data[i].incoming_signalled =
vsoc_dev.kernel_mapped_shm + shm_off_to_virtual_addr(region->region_begin_offset) +
region->region_begin_offset +
h_to_g_signal_table->interrupt_signalled_offset; h_to_g_signal_table->interrupt_signalled_offset;
vsoc_dev.regions_data[i].outgoing_signalled = vsoc_dev.regions_data[i].outgoing_signalled =
vsoc_dev.kernel_mapped_shm + shm_off_to_virtual_addr(region->region_begin_offset) +
region->region_begin_offset +
g_to_h_signal_table->interrupt_signalled_offset; g_to_h_signal_table->interrupt_signalled_offset;
result = request_irq( result = request_irq(
vsoc_dev.msix_entries[i].vector, vsoc_dev.msix_entries[i].vector,
vsoc_interrupt, 0, vsoc_interrupt, 0,
...@@ -948,7 +946,7 @@ static int vsoc_probe_device(struct pci_dev *pdev, ...@@ -948,7 +946,7 @@ static int vsoc_probe_device(struct pci_dev *pdev,
vsoc_remove_device(pdev); vsoc_remove_device(pdev);
return -ENOSPC; return -ENOSPC;
} }
vsoc_dev.regions_data[i].irq_requested = 1; vsoc_dev.regions_data[i].irq_requested = true;
if (!device_create(vsoc_dev.class, NULL, if (!device_create(vsoc_dev.class, NULL,
MKDEV(vsoc_dev.major, i), MKDEV(vsoc_dev.major, i),
NULL, vsoc_dev.regions_data[i].name)) { NULL, vsoc_dev.regions_data[i].name)) {
...@@ -956,7 +954,7 @@ static int vsoc_probe_device(struct pci_dev *pdev, ...@@ -956,7 +954,7 @@ static int vsoc_probe_device(struct pci_dev *pdev,
vsoc_remove_device(pdev); vsoc_remove_device(pdev);
return -EBUSY; return -EBUSY;
} }
vsoc_dev.regions_data[i].device_created = 1; vsoc_dev.regions_data[i].device_created = true;
} }
return 0; return 0;
} }
...@@ -988,51 +986,51 @@ static void vsoc_remove_device(struct pci_dev *pdev) ...@@ -988,51 +986,51 @@ static void vsoc_remove_device(struct pci_dev *pdev)
if (vsoc_dev.regions_data[i].device_created) { if (vsoc_dev.regions_data[i].device_created) {
device_destroy(vsoc_dev.class, device_destroy(vsoc_dev.class,
MKDEV(vsoc_dev.major, i)); MKDEV(vsoc_dev.major, i));
vsoc_dev.regions_data[i].device_created = 0; vsoc_dev.regions_data[i].device_created = false;
} }
if (vsoc_dev.regions_data[i].irq_requested) if (vsoc_dev.regions_data[i].irq_requested)
free_irq(vsoc_dev.msix_entries[i].vector, NULL); free_irq(vsoc_dev.msix_entries[i].vector, NULL);
vsoc_dev.regions_data[i].irq_requested = 0; vsoc_dev.regions_data[i].irq_requested = false;
} }
kfree(vsoc_dev.regions_data); kfree(vsoc_dev.regions_data);
vsoc_dev.regions_data = 0; vsoc_dev.regions_data = NULL;
} }
if (vsoc_dev.msix_enabled) { if (vsoc_dev.msix_enabled) {
pci_disable_msix(pdev); pci_disable_msix(pdev);
vsoc_dev.msix_enabled = 0; vsoc_dev.msix_enabled = false;
} }
kfree(vsoc_dev.msix_entries); kfree(vsoc_dev.msix_entries);
vsoc_dev.msix_entries = 0; vsoc_dev.msix_entries = NULL;
vsoc_dev.regions = 0; vsoc_dev.regions = NULL;
if (vsoc_dev.class_added) { if (vsoc_dev.class_added) {
class_destroy(vsoc_dev.class); class_destroy(vsoc_dev.class);
vsoc_dev.class_added = 0; vsoc_dev.class_added = false;
} }
if (vsoc_dev.cdev_added) { if (vsoc_dev.cdev_added) {
cdev_del(&vsoc_dev.cdev); cdev_del(&vsoc_dev.cdev);
vsoc_dev.cdev_added = 0; vsoc_dev.cdev_added = false;
} }
if (vsoc_dev.major && vsoc_dev.layout) { if (vsoc_dev.major && vsoc_dev.layout) {
unregister_chrdev_region(MKDEV(vsoc_dev.major, 0), unregister_chrdev_region(MKDEV(vsoc_dev.major, 0),
vsoc_dev.layout->region_count); vsoc_dev.layout->region_count);
vsoc_dev.major = 0; vsoc_dev.major = 0;
} }
vsoc_dev.layout = 0; vsoc_dev.layout = NULL;
if (vsoc_dev.kernel_mapped_shm) { if (vsoc_dev.kernel_mapped_shm) {
pci_iounmap(pdev, vsoc_dev.kernel_mapped_shm); pci_iounmap(pdev, vsoc_dev.kernel_mapped_shm);
vsoc_dev.kernel_mapped_shm = 0; vsoc_dev.kernel_mapped_shm = NULL;
} }
if (vsoc_dev.regs) { if (vsoc_dev.regs) {
pci_iounmap(pdev, vsoc_dev.regs); pci_iounmap(pdev, vsoc_dev.regs);
vsoc_dev.regs = 0; vsoc_dev.regs = NULL;
} }
if (vsoc_dev.requested_regions) { if (vsoc_dev.requested_regions) {
pci_release_regions(pdev); pci_release_regions(pdev);
vsoc_dev.requested_regions = 0; vsoc_dev.requested_regions = false;
} }
if (vsoc_dev.enabled_device) { if (vsoc_dev.enabled_device) {
pci_disable_device(pdev); pci_disable_device(pdev);
vsoc_dev.enabled_device = 0; vsoc_dev.enabled_device = false;
} }
/* Do this last: it indicates that the device is not initialized. */ /* Do this last: it indicates that the device is not initialized. */
vsoc_dev.dev = NULL; vsoc_dev.dev = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment