Received: by 10.192.165.148 with SMTP id m20csp1412956imm; Wed, 2 May 2018 21:48:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpMI8EGCP2BjXUZY43RIcH8swLDTqI4w4RSnJeN6I+kpI6GNBU+NjhWPnrsTlKtL5DbNchG X-Received: by 2002:a17:902:6b45:: with SMTP id g5-v6mr7995330plt.67.1525322927768; Wed, 02 May 2018 21:48:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525322927; cv=none; d=google.com; s=arc-20160816; b=MfQxHpqCVQDg1q4g8YMQ/87ZM5oZ1uhO7iqMnjOUyHc6snDAL6HpH91UxrvDCRRhwy MCEIRpBiwNdqJElOgHDnJYRoGgansz4FyW3/r6HnruhvX4A87rut5+pVFsKKumj4m8pj NsuVud0/1lXsCGjyL6R16zQyWygetP9PtWroxR1Bt8JRv75gpsh2LqdZJO6aI0VKnXKf Tdr9tSGLprk64PiDJYlJIEyb5BTfXimMhqrN7eXLd2FMcQaRSe70JLJrIxDsfLpiaPJ+ Sks2i+O5Y+xyUZ5AmZnDRzR4TeHmuJd5/XviaYs+biidi7uFQDgpDKXq0V9e+h/+7f/r qWZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=xtsnCmNrJ8vGXMPgAzCX57P/FvEog2LgYBZUNeXcFcI=; b=r8yszQDl2P7S7csj2lhcp6VY2S42fHsfRryG3pP7Wo3we05xok05Xf7g4AftS+6St1 6e0kXfYok671BbNpfm+gfgb3MWImxd/Oy5Wd2Wg1voCwJEAgGqo1RlVo5H9VgyF/Kbe1 IKo80qm7wV28kjH4Rqx8+AZNhwGFznNYp7vkWFECmWJokqqUT9W7OskgNf0q6ZG+rGI6 CXrb1Z43Jlt6uW9E/HrqlhYu7QAruWn5JIusqq2Nyg+YiCEfT/hMXhdPEsED1k1EA+2s J7M+UzB8ewS92LEXaEAvleyPrrnwJvfpkEWy+EkoU/4jrgXN9CG4evlznI92ktcPYXdn t+ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KgTEM9Qw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f131si7378413pfc.316.2018.05.02.21.48.33; Wed, 02 May 2018 21:48:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KgTEM9Qw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752119AbeECEqZ (ORCPT + 99 others); Thu, 3 May 2018 00:46:25 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:43576 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752076AbeECEqY (ORCPT ); Thu, 3 May 2018 00:46:24 -0400 Received: by mail-pg0-f68.google.com with SMTP id k11-v6so11111402pgo.10 for ; Wed, 02 May 2018 21:46:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xtsnCmNrJ8vGXMPgAzCX57P/FvEog2LgYBZUNeXcFcI=; b=KgTEM9Qw1/R2dMaNsiHNU8/SV9woX3HHbjlOIVDpVN6lU0jPnPLMWWd5VTGDyJQnYu 98CrAJizrf7FoDDK29XXpXBJt/NIujuABDO7JJmMo1DXH8Z8De3/P7xbqS+u7XSLEez0 YGz9Y75dRz02uG1Ornlh/sP9u17MsXt0QqKTJvfnd6p0CspKZgp4oyeMbIc1Kw6eXX3w XHhicHx4WJeIM6PwUprS5ka8fL9ZrEsQcLhYUI+CFQATkqfA4rMv90zdTomjeYiUFgso zt+JKSUpwstMxnDdSJU5Drzmz4VeABbM/sg9jV0eMxjhfgVvJ1xHefvnsE8H+AKcysNG Lszw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xtsnCmNrJ8vGXMPgAzCX57P/FvEog2LgYBZUNeXcFcI=; b=fYvCN+BZpHqLjNCjtTV7XZMX2Spi+6tyfz3i7dM2wiuZ7arpHOX3aWOuOoYnqUZBYz zCz0wtYQl7Yt7T2YABMVOMIeJWjL/0RUWymrffgxR1x6xZ+HBn4Pd4OU0CYTgPcYGuxu WIWl/tZy+pZqIZKK4c0rqnGgLxIHulkGnulf7HuAZTwJi1ijK6uG12brf1uaqtIr7c34 r7hDqe9xC7ApshhE9pIlHDIN6fugSxeXi4fLGAu+VgiRl+Vp5AX7y08XMoZYTe16Vkrg wUDPaGguU1fc953jo8fTh9i+tWeR2Q4TiyBKNewCoMXoOHLHF2lLTbtGaCqTR5KPlj6L Oqqw== X-Gm-Message-State: ALQs6tC1M6u8x3YNdyvF/b+NayP3pkMIt3bzDRx+tvH+xlJcr2tLisw/ I59QRfa6pIplflIqTSsyxuvtWUG/crkCTw== X-Received: by 2002:a17:902:9a90:: with SMTP id w16-v6mr22499078plp.390.1525322783100; Wed, 02 May 2018 21:46:23 -0700 (PDT) Received: from astrachan.mtv.corp.google.com ([2620:0:1000:1600:4394:e3d:8eee:a828]) by smtp.gmail.com with ESMTPSA id h191-v6sm21662997pgc.11.2018.05.02.21.46.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 May 2018 21:46:22 -0700 (PDT) From: Alistair Strachan To: linux-kernel@vger.kernel.org Cc: Alistair Strachan , Greg Kroah-Hartman , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Martijn Coenen , Greg Hartman , devel@driverdev.osuosl.org, kernel-team@android.com Subject: [PATCH 3/3] staging: Android: Fix sparse warnings in vsoc driver. Date: Wed, 2 May 2018 21:46:16 -0700 Message-Id: <20180503044616.157167-1-astrachan@google.com> X-Mailer: git-send-email 2.17.0.441.gb46fe60e1d-goog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman Cc: Arve Hjønnevåg Cc: Todd Kjos Cc: Martijn Coenen Cc: Greg Hartman Cc: devel@driverdev.osuosl.org Cc: kernel-team@android.com Signed-off-by: Alistair Strachan --- drivers/staging/android/vsoc.c | 100 ++++++++++++++++----------------- 1 file changed, 49 insertions(+), 51 deletions(-) diff --git a/drivers/staging/android/vsoc.c b/drivers/staging/android/vsoc.c index 3e6e4af7d6a1..954ed2c5d807 100644 --- a/drivers/staging/android/vsoc.c +++ b/drivers/staging/android/vsoc.c @@ -81,8 +81,8 @@ struct vsoc_region_data { atomic_t *incoming_signalled; /* Flag indicating the guest has signalled the host. */ atomic_t *outgoing_signalled; - int irq_requested; - int device_created; + bool irq_requested; + bool device_created; }; struct vsoc_device { @@ -91,7 +91,7 @@ struct vsoc_device { /* Physical address of SHARED_MEMORY_BAR. */ phys_addr_t shm_phys_start; /* 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_t shm_size; /* @@ -116,22 +116,23 @@ struct vsoc_device { * vsoc_region_data because the kernel deals with them as an array. */ 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 */ struct mutex mtx; /* Major number assigned by the kernel */ int major; - + /* Character device assigned by the kernel */ struct cdev cdev; + /* Device class assigned by the kernel */ 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; @@ -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_open(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_write(struct file *, const 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 __user *, size_t, loff_t *); static loff_t vsoc_lseek(struct file *filp, loff_t offset, int origin); static int do_create_fd_scoped_permission( struct vsoc_device_region *region_p, 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( struct vsoc_device_region *owner_region_p, struct fd_scoped_permission *perm); @@ -198,7 +199,7 @@ inline int vsoc_validate_filep(struct file *filp) /* Converts from shared memory offset to virtual address */ 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 */ @@ -261,7 +262,7 @@ static struct pci_driver vsoc_pci_driver = { static int do_create_fd_scoped_permission( struct vsoc_device_region *region_p, struct fd_scoped_permission_node *np, - struct fd_scoped_permission_arg *__user arg) + struct fd_scoped_permission_arg __user *arg) { struct file *managed_filp; s32 managed_fd; @@ -632,11 +633,11 @@ static long vsoc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 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) { __u32 area_off; - void *area_p; + const void *area_p; ssize_t area_len; int retval = vsoc_validate_filep(filp); @@ -706,7 +707,7 @@ static loff_t vsoc_lseek(struct file *filp, loff_t offset, int origin) 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) { __u32 area_off; @@ -772,14 +773,14 @@ static int vsoc_probe_device(struct pci_dev *pdev, pci_name(pdev), result); return result; } - vsoc_dev.enabled_device = 1; + vsoc_dev.enabled_device = true; result = pci_request_regions(pdev, "vsoc"); if (result < 0) { dev_err(&pdev->dev, "pci_request_regions failed\n"); vsoc_remove_device(pdev); return -EBUSY; } - vsoc_dev.requested_regions = 1; + vsoc_dev.requested_regions = true; /* Set up the control registers in BAR 0 */ reg_size = pci_resource_len(pdev, REGISTER_BAR); if (reg_size > MAX_REGISTER_BAR_LEN) @@ -790,7 +791,7 @@ static int vsoc_probe_device(struct pci_dev *pdev, if (!vsoc_dev.regs) { dev_err(&pdev->dev, - "cannot ioremap registers of size %zu\n", + "cannot map registers of size %zu\n", (size_t)reg_size); vsoc_remove_device(pdev); return -EBUSY; @@ -809,8 +810,8 @@ static int vsoc_probe_device(struct pci_dev *pdev, return -EBUSY; } - vsoc_dev.layout = - (struct vsoc_shm_layout_descriptor *)vsoc_dev.kernel_mapped_shm; + vsoc_dev.layout = (struct vsoc_shm_layout_descriptor __force *) + vsoc_dev.kernel_mapped_shm; dev_info(&pdev->dev, "major_version: %d\n", vsoc_dev.layout->major_version); dev_info(&pdev->dev, "minor_version: %d\n", @@ -841,16 +842,16 @@ static int vsoc_probe_device(struct pci_dev *pdev, vsoc_remove_device(pdev); return -EBUSY; } - vsoc_dev.cdev_added = 1; + vsoc_dev.cdev_added = true; vsoc_dev.class = class_create(THIS_MODULE, VSOC_DEV_NAME); if (IS_ERR(vsoc_dev.class)) { dev_err(&vsoc_dev.dev->dev, "class_create failed\n"); vsoc_remove_device(pdev); return PTR_ERR(vsoc_dev.class); } - vsoc_dev.class_added = 1; - vsoc_dev.regions = (struct vsoc_device_region *) - (vsoc_dev.kernel_mapped_shm + + vsoc_dev.class_added = true; + vsoc_dev.regions = (struct vsoc_device_region __force *) + ((void *)vsoc_dev.layout + vsoc_dev.layout->vsoc_region_desc_offset); vsoc_dev.msix_entries = kcalloc( vsoc_dev.layout->region_count, @@ -910,7 +911,7 @@ static int vsoc_probe_device(struct pci_dev *pdev, return -EFAULT; } } - vsoc_dev.msix_enabled = 1; + vsoc_dev.msix_enabled = true; for (i = 0; i < vsoc_dev.layout->region_count; ++i) { const struct vsoc_device_region *region = vsoc_dev.regions + i; 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, &vsoc_dev.regions_data[i].interrupt_wait_queue); init_waitqueue_head(&vsoc_dev.regions_data[i].futex_wait_queue); vsoc_dev.regions_data[i].incoming_signalled = - vsoc_dev.kernel_mapped_shm + - region->region_begin_offset + + shm_off_to_virtual_addr(region->region_begin_offset) + h_to_g_signal_table->interrupt_signalled_offset; vsoc_dev.regions_data[i].outgoing_signalled = - vsoc_dev.kernel_mapped_shm + - region->region_begin_offset + + shm_off_to_virtual_addr(region->region_begin_offset) + g_to_h_signal_table->interrupt_signalled_offset; - result = request_irq( vsoc_dev.msix_entries[i].vector, vsoc_interrupt, 0, @@ -948,7 +946,7 @@ static int vsoc_probe_device(struct pci_dev *pdev, vsoc_remove_device(pdev); 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, MKDEV(vsoc_dev.major, i), NULL, vsoc_dev.regions_data[i].name)) { @@ -956,7 +954,7 @@ static int vsoc_probe_device(struct pci_dev *pdev, vsoc_remove_device(pdev); return -EBUSY; } - vsoc_dev.regions_data[i].device_created = 1; + vsoc_dev.regions_data[i].device_created = true; } return 0; } @@ -988,51 +986,51 @@ static void vsoc_remove_device(struct pci_dev *pdev) if (vsoc_dev.regions_data[i].device_created) { device_destroy(vsoc_dev.class, 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) 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); - vsoc_dev.regions_data = 0; + vsoc_dev.regions_data = NULL; } if (vsoc_dev.msix_enabled) { pci_disable_msix(pdev); - vsoc_dev.msix_enabled = 0; + vsoc_dev.msix_enabled = false; } kfree(vsoc_dev.msix_entries); - vsoc_dev.msix_entries = 0; - vsoc_dev.regions = 0; + vsoc_dev.msix_entries = NULL; + vsoc_dev.regions = NULL; if (vsoc_dev.class_added) { class_destroy(vsoc_dev.class); - vsoc_dev.class_added = 0; + vsoc_dev.class_added = false; } if (vsoc_dev.cdev_added) { cdev_del(&vsoc_dev.cdev); - vsoc_dev.cdev_added = 0; + vsoc_dev.cdev_added = false; } if (vsoc_dev.major && vsoc_dev.layout) { unregister_chrdev_region(MKDEV(vsoc_dev.major, 0), vsoc_dev.layout->region_count); vsoc_dev.major = 0; } - vsoc_dev.layout = 0; + vsoc_dev.layout = NULL; if (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) { pci_iounmap(pdev, vsoc_dev.regs); - vsoc_dev.regs = 0; + vsoc_dev.regs = NULL; } if (vsoc_dev.requested_regions) { pci_release_regions(pdev); - vsoc_dev.requested_regions = 0; + vsoc_dev.requested_regions = false; } if (vsoc_dev.enabled_device) { 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. */ vsoc_dev.dev = NULL;