All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Arvind Yadav <arvind.yadav.cs@gmail.com>,
	Helge Deller <deller@gmx.de>,
	Sasha Levin <alexander.levin@verizon.com>
Subject: [PATCH 4.4 39/50] parisc: perf: Fix potential NULL pointer dereference
Date: Fri,  6 Oct 2017 10:53:27 +0200	[thread overview]
Message-ID: <20171006083711.486610697@linuxfoundation.org> (raw)
In-Reply-To: <20171006083705.157012217@linuxfoundation.org>

4.4-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Arvind Yadav <arvind.yadav.cs@gmail.com>


[ Upstream commit 74e3f6e63da6c8e8246fba1689e040bc926b4a1a ]

Fix potential NULL pointer dereference and clean up
coding style errors (code indent, trailing whitespaces).

Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
Signed-off-by: Helge Deller <deller@gmx.de>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 arch/parisc/kernel/perf.c |   94 +++++++++++++++++++++++-----------------------
 1 file changed, 49 insertions(+), 45 deletions(-)

--- a/arch/parisc/kernel/perf.c
+++ b/arch/parisc/kernel/perf.c
@@ -39,7 +39,7 @@
  *  the PDC INTRIGUE calls.  This is done to eliminate bugs introduced
  *  in various PDC revisions.  The code is much more maintainable
  *  and reliable this way vs having to debug on every version of PDC
- *  on every box. 
+ *  on every box.
  */
 
 #include <linux/capability.h>
@@ -195,8 +195,8 @@ static int perf_config(uint32_t *image_p
 static int perf_release(struct inode *inode, struct file *file);
 static int perf_open(struct inode *inode, struct file *file);
 static ssize_t perf_read(struct file *file, char __user *buf, size_t cnt, loff_t *ppos);
-static ssize_t perf_write(struct file *file, const char __user *buf, size_t count, 
-	loff_t *ppos);
+static ssize_t perf_write(struct file *file, const char __user *buf,
+	size_t count, loff_t *ppos);
 static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
 static void perf_start_counters(void);
 static int perf_stop_counters(uint32_t *raddr);
@@ -222,7 +222,7 @@ extern void perf_intrigue_disable_perf_c
 /*
  * configure:
  *
- * Configure the cpu with a given data image.  First turn off the counters, 
+ * Configure the cpu with a given data image.  First turn off the counters,
  * then download the image, then turn the counters back on.
  */
 static int perf_config(uint32_t *image_ptr)
@@ -234,7 +234,7 @@ static int perf_config(uint32_t *image_p
 	error = perf_stop_counters(raddr);
 	if (error != 0) {
 		printk("perf_config: perf_stop_counters = %ld\n", error);
-		return -EINVAL; 
+		return -EINVAL;
 	}
 
 printk("Preparing to write image\n");
@@ -242,7 +242,7 @@ printk("Preparing to write image\n");
 	error = perf_write_image((uint64_t *)image_ptr);
 	if (error != 0) {
 		printk("perf_config: DOWNLOAD = %ld\n", error);
-		return -EINVAL; 
+		return -EINVAL;
 	}
 
 printk("Preparing to start counters\n");
@@ -254,7 +254,7 @@ printk("Preparing to start counters\n");
 }
 
 /*
- * Open the device and initialize all of its memory.  The device is only 
+ * Open the device and initialize all of its memory.  The device is only
  * opened once, but can be "queried" by multiple processes that know its
  * file descriptor.
  */
@@ -298,8 +298,8 @@ static ssize_t perf_read(struct file *fi
  * called on the processor that the download should happen
  * on.
  */
-static ssize_t perf_write(struct file *file, const char __user *buf, size_t count, 
-	loff_t *ppos)
+static ssize_t perf_write(struct file *file, const char __user *buf,
+	size_t count, loff_t *ppos)
 {
 	int err;
 	size_t image_size;
@@ -307,11 +307,11 @@ static ssize_t perf_write(struct file *f
 	uint32_t interface_type;
 	uint32_t test;
 
-	if (perf_processor_interface == ONYX_INTF) 
+	if (perf_processor_interface == ONYX_INTF)
 		image_size = PCXU_IMAGE_SIZE;
-	else if (perf_processor_interface == CUDA_INTF) 
+	else if (perf_processor_interface == CUDA_INTF)
 		image_size = PCXW_IMAGE_SIZE;
-	else 
+	else
 		return -EFAULT;
 
 	if (!capable(CAP_SYS_ADMIN))
@@ -331,22 +331,22 @@ static ssize_t perf_write(struct file *f
 
 	/* First check the machine type is correct for
 	   the requested image */
-        if (((perf_processor_interface == CUDA_INTF) &&
-		       (interface_type != CUDA_INTF)) ||
-	    ((perf_processor_interface == ONYX_INTF) &&
-	               (interface_type != ONYX_INTF))) 
+	if (((perf_processor_interface == CUDA_INTF) &&
+			(interface_type != CUDA_INTF)) ||
+		((perf_processor_interface == ONYX_INTF) &&
+			(interface_type != ONYX_INTF)))
 		return -EINVAL;
 
 	/* Next check to make sure the requested image
 	   is valid */
-	if (((interface_type == CUDA_INTF) && 
+	if (((interface_type == CUDA_INTF) &&
 		       (test >= MAX_CUDA_IMAGES)) ||
-	    ((interface_type == ONYX_INTF) && 
-		       (test >= MAX_ONYX_IMAGES))) 
+	    ((interface_type == ONYX_INTF) &&
+		       (test >= MAX_ONYX_IMAGES)))
 		return -EINVAL;
 
 	/* Copy the image into the processor */
-	if (interface_type == CUDA_INTF) 
+	if (interface_type == CUDA_INTF)
 		return perf_config(cuda_images[test]);
 	else
 		return perf_config(onyx_images[test]);
@@ -360,7 +360,7 @@ static ssize_t perf_write(struct file *f
 static void perf_patch_images(void)
 {
 #if 0 /* FIXME!! */
-/* 
+/*
  * NOTE:  this routine is VERY specific to the current TLB image.
  * If the image is changed, this routine might also need to be changed.
  */
@@ -368,9 +368,9 @@ static void perf_patch_images(void)
 	extern void $i_dtlb_miss_2_0();
 	extern void PA2_0_iva();
 
-	/* 
+	/*
 	 * We can only use the lower 32-bits, the upper 32-bits should be 0
-	 * anyway given this is in the kernel 
+	 * anyway given this is in the kernel
 	 */
 	uint32_t itlb_addr  = (uint32_t)&($i_itlb_miss_2_0);
 	uint32_t dtlb_addr  = (uint32_t)&($i_dtlb_miss_2_0);
@@ -378,21 +378,21 @@ static void perf_patch_images(void)
 
 	if (perf_processor_interface == ONYX_INTF) {
 		/* clear last 2 bytes */
-		onyx_images[TLBMISS][15] &= 0xffffff00;  
+		onyx_images[TLBMISS][15] &= 0xffffff00;
 		/* set 2 bytes */
 		onyx_images[TLBMISS][15] |= (0x000000ff&((dtlb_addr) >> 24));
 		onyx_images[TLBMISS][16] = (dtlb_addr << 8)&0xffffff00;
 		onyx_images[TLBMISS][17] = itlb_addr;
 
 		/* clear last 2 bytes */
-		onyx_images[TLBHANDMISS][15] &= 0xffffff00;  
+		onyx_images[TLBHANDMISS][15] &= 0xffffff00;
 		/* set 2 bytes */
 		onyx_images[TLBHANDMISS][15] |= (0x000000ff&((dtlb_addr) >> 24));
 		onyx_images[TLBHANDMISS][16] = (dtlb_addr << 8)&0xffffff00;
 		onyx_images[TLBHANDMISS][17] = itlb_addr;
 
 		/* clear last 2 bytes */
-		onyx_images[BIG_CPI][15] &= 0xffffff00;  
+		onyx_images[BIG_CPI][15] &= 0xffffff00;
 		/* set 2 bytes */
 		onyx_images[BIG_CPI][15] |= (0x000000ff&((dtlb_addr) >> 24));
 		onyx_images[BIG_CPI][16] = (dtlb_addr << 8)&0xffffff00;
@@ -405,24 +405,24 @@ static void perf_patch_images(void)
 
 	} else if (perf_processor_interface == CUDA_INTF) {
 		/* Cuda interface */
-		cuda_images[TLBMISS][16] =  
+		cuda_images[TLBMISS][16] =
 			(cuda_images[TLBMISS][16]&0xffff0000) |
 			((dtlb_addr >> 8)&0x0000ffff);
-		cuda_images[TLBMISS][17] = 
+		cuda_images[TLBMISS][17] =
 			((dtlb_addr << 24)&0xff000000) | ((itlb_addr >> 16)&0x000000ff);
 		cuda_images[TLBMISS][18] = (itlb_addr << 16)&0xffff0000;
 
-		cuda_images[TLBHANDMISS][16] = 
+		cuda_images[TLBHANDMISS][16] =
 			(cuda_images[TLBHANDMISS][16]&0xffff0000) |
 			((dtlb_addr >> 8)&0x0000ffff);
-		cuda_images[TLBHANDMISS][17] = 
+		cuda_images[TLBHANDMISS][17] =
 			((dtlb_addr << 24)&0xff000000) | ((itlb_addr >> 16)&0x000000ff);
 		cuda_images[TLBHANDMISS][18] = (itlb_addr << 16)&0xffff0000;
 
-		cuda_images[BIG_CPI][16] = 
+		cuda_images[BIG_CPI][16] =
 			(cuda_images[BIG_CPI][16]&0xffff0000) |
 			((dtlb_addr >> 8)&0x0000ffff);
-		cuda_images[BIG_CPI][17] = 
+		cuda_images[BIG_CPI][17] =
 			((dtlb_addr << 24)&0xff000000) | ((itlb_addr >> 16)&0x000000ff);
 		cuda_images[BIG_CPI][18] = (itlb_addr << 16)&0xffff0000;
 	} else {
@@ -434,7 +434,7 @@ static void perf_patch_images(void)
 
 /*
  * ioctl routine
- * All routines effect the processor that they are executed on.  Thus you 
+ * All routines effect the processor that they are executed on.  Thus you
  * must be running on the processor that you wish to change.
  */
 
@@ -460,7 +460,7 @@ static long perf_ioctl(struct file *file
 			}
 
 			/* copy out the Counters */
-			if (copy_to_user((void __user *)arg, raddr, 
+			if (copy_to_user((void __user *)arg, raddr,
 					sizeof (raddr)) != 0) {
 				error =  -EFAULT;
 				break;
@@ -488,7 +488,7 @@ static const struct file_operations perf
 	.open = perf_open,
 	.release = perf_release
 };
-	
+
 static struct miscdevice perf_dev = {
 	MISC_DYNAMIC_MINOR,
 	PA_PERF_DEV,
@@ -596,7 +596,7 @@ static int perf_stop_counters(uint32_t *
 		/* OR sticky2 (bit 1496) to counter2 bit 32 */
 		tmp64 |= (userbuf[23] >> 8) & 0x0000000080000000;
 		raddr[2] = (uint32_t)tmp64;
-		
+
 		/* Counter3 is bits 1497 to 1528 */
 		tmp64 =  (userbuf[23] >> 7) & 0x00000000ffffffff;
 		/* OR sticky3 (bit 1529) to counter3 bit 32 */
@@ -618,7 +618,7 @@ static int perf_stop_counters(uint32_t *
 		userbuf[22] = 0;
 		userbuf[23] = 0;
 
-		/* 
+		/*
 		 * Write back the zeroed bytes + the image given
 		 * the read was destructive.
 		 */
@@ -626,13 +626,13 @@ static int perf_stop_counters(uint32_t *
 	} else {
 
 		/*
-		 * Read RDR-15 which contains the counters and sticky bits 
+		 * Read RDR-15 which contains the counters and sticky bits
 		 */
 		if (!perf_rdr_read_ubuf(15, userbuf)) {
 			return -13;
 		}
 
-		/* 
+		/*
 		 * Clear out the counters
 		 */
 		perf_rdr_clear(15);
@@ -645,7 +645,7 @@ static int perf_stop_counters(uint32_t *
 		raddr[2] = (uint32_t)((userbuf[1] >> 32) & 0x00000000ffffffffUL);
 		raddr[3] = (uint32_t)(userbuf[1] & 0x00000000ffffffffUL);
 	}
- 
+
 	return 0;
 }
 
@@ -683,7 +683,7 @@ static int perf_rdr_read_ubuf(uint32_t	r
 	i = tentry->num_words;
 	while (i--) {
 		buffer[i] = 0;
-	}	
+	}
 
 	/* Check for bits an even number of 64 */
 	if ((xbits = width & 0x03f) != 0) {
@@ -809,18 +809,22 @@ static int perf_write_image(uint64_t *me
 	}
 
 	runway = ioremap_nocache(cpu_device->hpa.start, 4096);
+	if (!runway) {
+		pr_err("perf_write_image: ioremap failed!\n");
+		return -ENOMEM;
+	}
 
 	/* Merge intrigue bits into Runway STATUS 0 */
 	tmp64 = __raw_readq(runway + RUNWAY_STATUS) & 0xffecfffffffffffful;
-	__raw_writeq(tmp64 | (*memaddr++ & 0x0013000000000000ul), 
+	__raw_writeq(tmp64 | (*memaddr++ & 0x0013000000000000ul),
 		     runway + RUNWAY_STATUS);
-	
+
 	/* Write RUNWAY DEBUG registers */
 	for (i = 0; i < 8; i++) {
 		__raw_writeq(*memaddr++, runway + RUNWAY_DEBUG);
 	}
 
-	return 0; 
+	return 0;
 }
 
 /*
@@ -844,7 +848,7 @@ printk("perf_rdr_write\n");
 			perf_rdr_shift_out_U(rdr_num, buffer[i]);
 		} else {
 			perf_rdr_shift_out_W(rdr_num, buffer[i]);
-		}	
+		}
 	}
 printk("perf_rdr_write done\n");
 }

  parent reply	other threads:[~2017-10-06  8:58 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-06  8:52 [PATCH 4.4 00/50] 4.4.91-stable review Greg Kroah-Hartman
2017-10-06  8:52 ` [PATCH 4.4 01/50] drm_fourcc: Fix DRM_FORMAT_MOD_LINEAR #define Greg Kroah-Hartman
2017-10-06  8:52 ` [PATCH 4.4 02/50] drm: bridge: add DT bindings for TI ths8135 Greg Kroah-Hartman
2017-10-16 19:05   ` Ben Hutchings
2017-10-19  9:37     ` Greg Kroah-Hartman
2017-10-19  9:37       ` Greg Kroah-Hartman
2017-10-19 15:32       ` Levin, Alexander (Sasha Levin)
2017-10-31  9:50         ` Greg Kroah-Hartman
2017-10-31  9:50           ` Greg Kroah-Hartman
2017-10-06  8:52 ` [PATCH 4.4 03/50] GFS2: Fix reference to ERR_PTR in gfs2_glock_iter_next Greg Kroah-Hartman
2017-10-06  8:52 ` [PATCH 4.4 04/50] RDS: RDMA: Fix the composite message user notification Greg Kroah-Hartman
2017-10-06  8:52 ` [PATCH 4.4 05/50] ARM: dts: r8a7790: Use R-Car Gen 2 fallback binding for msiof nodes Greg Kroah-Hartman
2017-10-06  8:52 ` [PATCH 4.4 06/50] MIPS: Ensure bss section ends on a long-aligned address Greg Kroah-Hartman
2017-10-06  8:52 ` [PATCH 4.4 07/50] MIPS: ralink: Fix incorrect assignment on ralink_soc Greg Kroah-Hartman
2017-10-06  8:52 ` [PATCH 4.4 08/50] igb: re-assign hw address pointer on reset after PCI error Greg Kroah-Hartman
2017-10-06  8:52 ` [PATCH 4.4 09/50] extcon: axp288: Use vbus-valid instead of -present to determine cable presence Greg Kroah-Hartman
2017-10-06  8:52 ` [PATCH 4.4 11/50] hwmon: (gl520sm) Fix overflows and crash seen when writing into limit attributes Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 12/50] iio: adc: axp288: Drop bogus AXP288_ADC_TS_PIN_CTRL register modifications Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 13/50] iio: adc: hx711: Add DT binding for avia,hx711 Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 14/50] ARM: 8635/1: nommu: allow enabling REMAP_VECTORS_TO_RAM Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 15/50] tty: goldfish: Fix a parameter of a call to free_irq Greg Kroah-Hartman
2017-10-16 19:46   ` Ben Hutchings
2017-10-19  9:38     ` Greg Kroah-Hartman
2017-10-19  9:38       ` Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 16/50] IB/ipoib: Fix deadlock over vlan_mutex Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 17/50] IB/ipoib: rtnl_unlock can not come after free_netdev Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 18/50] IB/ipoib: Replace list_del of the neigh->list with list_del_init Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 19/50] drm/amdkfd: fix improper return value on error Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 20/50] USB: serial: mos7720: fix control-message error handling Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 21/50] USB: serial: mos7840: " Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 22/50] pinctrl: mvebu: Use seq_puts() in mvebu_pinconf_group_dbg_show() Greg Kroah-Hartman
2017-10-06  9:09   ` Joe Perches
2017-10-06  9:20     ` Greg Kroah-Hartman
2017-10-06 14:16       ` Levin, Alexander (Sasha Levin)
2017-10-06  8:53 ` [PATCH 4.4 23/50] partitions/efi: Fix integer overflow in GPT size calculation Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 24/50] ASoC: dapm: handle probe deferrals Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 25/50] audit: log 32-bit socketcalls Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 26/50] usb: chipidea: vbus event may exist before starting gadget Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 27/50] ASoC: dapm: fix some pointer error handling Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 28/50] MIPS: Lantiq: Fix another request_mem_region() return code check Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 29/50] net: core: Prevent from dereferencing null pointer when releasing SKB Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 30/50] net/packet: check length in getsockopt() called with PACKET_HDRLEN Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 31/50] team: fix memory leaks Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 33/50] mmc: sdio: fix alignment issue in struct sdio_func Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 34/50] bridge: netlink: register netdevice before executing changelink Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 35/50] netfilter: invoke synchronize_rcu after set the _hook_ to NULL Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 36/50] MIPS: IRQ Stack: Unwind IRQ stack onto task stack Greg Kroah-Hartman
2017-10-16 21:28   ` Ben Hutchings
2017-10-17  7:18     ` Matt Redfearn
2017-10-17  7:18       ` Matt Redfearn
2017-10-19  9:36       ` Greg Kroah-Hartman
2017-10-19  9:36         ` Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 37/50] [media] exynos-gsc: Do not swap cb/cr for semi planar formats Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 38/50] netfilter: nfnl_cthelper: fix incorrect helper->expect_class_max Greg Kroah-Hartman
2017-10-06  8:53 ` Greg Kroah-Hartman [this message]
2017-10-06  8:53 ` [PATCH 4.4 40/50] iommu/io-pgtable-arm: Check for leaf entry before dereferencing it Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 41/50] rds: ib: add error handle Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 42/50] md/raid10: submit bio directly to replacement disk Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 43/50] i2c: meson: fix wrong variable usage in meson_i2c_put_data Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 44/50] xfs: remove kmem_zalloc_greedy Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 45/50] libata: transport: Remove circular dependency at free time Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 46/50] drivers: firmware: psci: drop duplicate const from psci_of_match Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 47/50] IB/qib: fix false-postive maybe-uninitialized warning Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 49/50] ALSA: au88x0: avoid theoretical uninitialized access Greg Kroah-Hartman
2017-10-06  8:53 ` [PATCH 4.4 50/50] [media] ttpci: address stringop overflow warning Greg Kroah-Hartman
2017-10-06 14:04 ` [PATCH 4.4 00/50] 4.4.91-stable review Guenter Roeck
2017-10-07 10:07   ` Greg Kroah-Hartman
2017-10-06 17:50 ` Shuah Khan
2017-10-07 16:56 ` Tom Gall
2017-10-07 16:56   ` Tom Gall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171006083711.486610697@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=alexander.levin@verizon.com \
    --cc=arvind.yadav.cs@gmail.com \
    --cc=deller@gmx.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.