Skip to content

Commit cadfa3a

Browse files
ArvindYadavCsgregkh
authored andcommitted
parisc: perf: Fix potential NULL pointer dereference
[ 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>
1 parent 4203f2a commit cadfa3a

1 file changed

Lines changed: 49 additions & 45 deletions

File tree

arch/parisc/kernel/perf.c

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* the PDC INTRIGUE calls. This is done to eliminate bugs introduced
4040
* in various PDC revisions. The code is much more maintainable
4141
* and reliable this way vs having to debug on every version of PDC
42-
* on every box.
42+
* on every box.
4343
*/
4444

4545
#include <linux/capability.h>
@@ -195,8 +195,8 @@ static int perf_config(uint32_t *image_ptr);
195195
static int perf_release(struct inode *inode, struct file *file);
196196
static int perf_open(struct inode *inode, struct file *file);
197197
static ssize_t perf_read(struct file *file, char __user *buf, size_t cnt, loff_t *ppos);
198-
static ssize_t perf_write(struct file *file, const char __user *buf, size_t count,
199-
loff_t *ppos);
198+
static ssize_t perf_write(struct file *file, const char __user *buf,
199+
size_t count, loff_t *ppos);
200200
static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
201201
static void perf_start_counters(void);
202202
static int perf_stop_counters(uint32_t *raddr);
@@ -222,7 +222,7 @@ extern void perf_intrigue_disable_perf_counters (void);
222222
/*
223223
* configure:
224224
*
225-
* Configure the cpu with a given data image. First turn off the counters,
225+
* Configure the cpu with a given data image. First turn off the counters,
226226
* then download the image, then turn the counters back on.
227227
*/
228228
static int perf_config(uint32_t *image_ptr)
@@ -234,15 +234,15 @@ static int perf_config(uint32_t *image_ptr)
234234
error = perf_stop_counters(raddr);
235235
if (error != 0) {
236236
printk("perf_config: perf_stop_counters = %ld\n", error);
237-
return -EINVAL;
237+
return -EINVAL;
238238
}
239239

240240
printk("Preparing to write image\n");
241241
/* Write the image to the chip */
242242
error = perf_write_image((uint64_t *)image_ptr);
243243
if (error != 0) {
244244
printk("perf_config: DOWNLOAD = %ld\n", error);
245-
return -EINVAL;
245+
return -EINVAL;
246246
}
247247

248248
printk("Preparing to start counters\n");
@@ -254,7 +254,7 @@ printk("Preparing to start counters\n");
254254
}
255255

256256
/*
257-
* Open the device and initialize all of its memory. The device is only
257+
* Open the device and initialize all of its memory. The device is only
258258
* opened once, but can be "queried" by multiple processes that know its
259259
* file descriptor.
260260
*/
@@ -298,20 +298,20 @@ static ssize_t perf_read(struct file *file, char __user *buf, size_t cnt, loff_t
298298
* called on the processor that the download should happen
299299
* on.
300300
*/
301-
static ssize_t perf_write(struct file *file, const char __user *buf, size_t count,
302-
loff_t *ppos)
301+
static ssize_t perf_write(struct file *file, const char __user *buf,
302+
size_t count, loff_t *ppos)
303303
{
304304
int err;
305305
size_t image_size;
306306
uint32_t image_type;
307307
uint32_t interface_type;
308308
uint32_t test;
309309

310-
if (perf_processor_interface == ONYX_INTF)
310+
if (perf_processor_interface == ONYX_INTF)
311311
image_size = PCXU_IMAGE_SIZE;
312-
else if (perf_processor_interface == CUDA_INTF)
312+
else if (perf_processor_interface == CUDA_INTF)
313313
image_size = PCXW_IMAGE_SIZE;
314-
else
314+
else
315315
return -EFAULT;
316316

317317
if (!capable(CAP_SYS_ADMIN))
@@ -331,22 +331,22 @@ static ssize_t perf_write(struct file *file, const char __user *buf, size_t coun
331331

332332
/* First check the machine type is correct for
333333
the requested image */
334-
if (((perf_processor_interface == CUDA_INTF) &&
335-
(interface_type != CUDA_INTF)) ||
336-
((perf_processor_interface == ONYX_INTF) &&
337-
(interface_type != ONYX_INTF)))
334+
if (((perf_processor_interface == CUDA_INTF) &&
335+
(interface_type != CUDA_INTF)) ||
336+
((perf_processor_interface == ONYX_INTF) &&
337+
(interface_type != ONYX_INTF)))
338338
return -EINVAL;
339339

340340
/* Next check to make sure the requested image
341341
is valid */
342-
if (((interface_type == CUDA_INTF) &&
342+
if (((interface_type == CUDA_INTF) &&
343343
(test >= MAX_CUDA_IMAGES)) ||
344-
((interface_type == ONYX_INTF) &&
345-
(test >= MAX_ONYX_IMAGES)))
344+
((interface_type == ONYX_INTF) &&
345+
(test >= MAX_ONYX_IMAGES)))
346346
return -EINVAL;
347347

348348
/* Copy the image into the processor */
349-
if (interface_type == CUDA_INTF)
349+
if (interface_type == CUDA_INTF)
350350
return perf_config(cuda_images[test]);
351351
else
352352
return perf_config(onyx_images[test]);
@@ -360,39 +360,39 @@ static ssize_t perf_write(struct file *file, const char __user *buf, size_t coun
360360
static void perf_patch_images(void)
361361
{
362362
#if 0 /* FIXME!! */
363-
/*
363+
/*
364364
* NOTE: this routine is VERY specific to the current TLB image.
365365
* If the image is changed, this routine might also need to be changed.
366366
*/
367367
extern void $i_itlb_miss_2_0();
368368
extern void $i_dtlb_miss_2_0();
369369
extern void PA2_0_iva();
370370

371-
/*
371+
/*
372372
* We can only use the lower 32-bits, the upper 32-bits should be 0
373-
* anyway given this is in the kernel
373+
* anyway given this is in the kernel
374374
*/
375375
uint32_t itlb_addr = (uint32_t)&($i_itlb_miss_2_0);
376376
uint32_t dtlb_addr = (uint32_t)&($i_dtlb_miss_2_0);
377377
uint32_t IVAaddress = (uint32_t)&PA2_0_iva;
378378

379379
if (perf_processor_interface == ONYX_INTF) {
380380
/* clear last 2 bytes */
381-
onyx_images[TLBMISS][15] &= 0xffffff00;
381+
onyx_images[TLBMISS][15] &= 0xffffff00;
382382
/* set 2 bytes */
383383
onyx_images[TLBMISS][15] |= (0x000000ff&((dtlb_addr) >> 24));
384384
onyx_images[TLBMISS][16] = (dtlb_addr << 8)&0xffffff00;
385385
onyx_images[TLBMISS][17] = itlb_addr;
386386

387387
/* clear last 2 bytes */
388-
onyx_images[TLBHANDMISS][15] &= 0xffffff00;
388+
onyx_images[TLBHANDMISS][15] &= 0xffffff00;
389389
/* set 2 bytes */
390390
onyx_images[TLBHANDMISS][15] |= (0x000000ff&((dtlb_addr) >> 24));
391391
onyx_images[TLBHANDMISS][16] = (dtlb_addr << 8)&0xffffff00;
392392
onyx_images[TLBHANDMISS][17] = itlb_addr;
393393

394394
/* clear last 2 bytes */
395-
onyx_images[BIG_CPI][15] &= 0xffffff00;
395+
onyx_images[BIG_CPI][15] &= 0xffffff00;
396396
/* set 2 bytes */
397397
onyx_images[BIG_CPI][15] |= (0x000000ff&((dtlb_addr) >> 24));
398398
onyx_images[BIG_CPI][16] = (dtlb_addr << 8)&0xffffff00;
@@ -405,24 +405,24 @@ static void perf_patch_images(void)
405405

406406
} else if (perf_processor_interface == CUDA_INTF) {
407407
/* Cuda interface */
408-
cuda_images[TLBMISS][16] =
408+
cuda_images[TLBMISS][16] =
409409
(cuda_images[TLBMISS][16]&0xffff0000) |
410410
((dtlb_addr >> 8)&0x0000ffff);
411-
cuda_images[TLBMISS][17] =
411+
cuda_images[TLBMISS][17] =
412412
((dtlb_addr << 24)&0xff000000) | ((itlb_addr >> 16)&0x000000ff);
413413
cuda_images[TLBMISS][18] = (itlb_addr << 16)&0xffff0000;
414414

415-
cuda_images[TLBHANDMISS][16] =
415+
cuda_images[TLBHANDMISS][16] =
416416
(cuda_images[TLBHANDMISS][16]&0xffff0000) |
417417
((dtlb_addr >> 8)&0x0000ffff);
418-
cuda_images[TLBHANDMISS][17] =
418+
cuda_images[TLBHANDMISS][17] =
419419
((dtlb_addr << 24)&0xff000000) | ((itlb_addr >> 16)&0x000000ff);
420420
cuda_images[TLBHANDMISS][18] = (itlb_addr << 16)&0xffff0000;
421421

422-
cuda_images[BIG_CPI][16] =
422+
cuda_images[BIG_CPI][16] =
423423
(cuda_images[BIG_CPI][16]&0xffff0000) |
424424
((dtlb_addr >> 8)&0x0000ffff);
425-
cuda_images[BIG_CPI][17] =
425+
cuda_images[BIG_CPI][17] =
426426
((dtlb_addr << 24)&0xff000000) | ((itlb_addr >> 16)&0x000000ff);
427427
cuda_images[BIG_CPI][18] = (itlb_addr << 16)&0xffff0000;
428428
} else {
@@ -434,7 +434,7 @@ static void perf_patch_images(void)
434434

435435
/*
436436
* ioctl routine
437-
* All routines effect the processor that they are executed on. Thus you
437+
* All routines effect the processor that they are executed on. Thus you
438438
* must be running on the processor that you wish to change.
439439
*/
440440

@@ -460,7 +460,7 @@ static long perf_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
460460
}
461461

462462
/* copy out the Counters */
463-
if (copy_to_user((void __user *)arg, raddr,
463+
if (copy_to_user((void __user *)arg, raddr,
464464
sizeof (raddr)) != 0) {
465465
error = -EFAULT;
466466
break;
@@ -488,7 +488,7 @@ static const struct file_operations perf_fops = {
488488
.open = perf_open,
489489
.release = perf_release
490490
};
491-
491+
492492
static struct miscdevice perf_dev = {
493493
MISC_DYNAMIC_MINOR,
494494
PA_PERF_DEV,
@@ -596,7 +596,7 @@ static int perf_stop_counters(uint32_t *raddr)
596596
/* OR sticky2 (bit 1496) to counter2 bit 32 */
597597
tmp64 |= (userbuf[23] >> 8) & 0x0000000080000000;
598598
raddr[2] = (uint32_t)tmp64;
599-
599+
600600
/* Counter3 is bits 1497 to 1528 */
601601
tmp64 = (userbuf[23] >> 7) & 0x00000000ffffffff;
602602
/* OR sticky3 (bit 1529) to counter3 bit 32 */
@@ -618,21 +618,21 @@ static int perf_stop_counters(uint32_t *raddr)
618618
userbuf[22] = 0;
619619
userbuf[23] = 0;
620620

621-
/*
621+
/*
622622
* Write back the zeroed bytes + the image given
623623
* the read was destructive.
624624
*/
625625
perf_rdr_write(16, userbuf);
626626
} else {
627627

628628
/*
629-
* Read RDR-15 which contains the counters and sticky bits
629+
* Read RDR-15 which contains the counters and sticky bits
630630
*/
631631
if (!perf_rdr_read_ubuf(15, userbuf)) {
632632
return -13;
633633
}
634634

635-
/*
635+
/*
636636
* Clear out the counters
637637
*/
638638
perf_rdr_clear(15);
@@ -645,7 +645,7 @@ static int perf_stop_counters(uint32_t *raddr)
645645
raddr[2] = (uint32_t)((userbuf[1] >> 32) & 0x00000000ffffffffUL);
646646
raddr[3] = (uint32_t)(userbuf[1] & 0x00000000ffffffffUL);
647647
}
648-
648+
649649
return 0;
650650
}
651651

@@ -683,7 +683,7 @@ static int perf_rdr_read_ubuf(uint32_t rdr_num, uint64_t *buffer)
683683
i = tentry->num_words;
684684
while (i--) {
685685
buffer[i] = 0;
686-
}
686+
}
687687

688688
/* Check for bits an even number of 64 */
689689
if ((xbits = width & 0x03f) != 0) {
@@ -809,18 +809,22 @@ static int perf_write_image(uint64_t *memaddr)
809809
}
810810

811811
runway = ioremap_nocache(cpu_device->hpa.start, 4096);
812+
if (!runway) {
813+
pr_err("perf_write_image: ioremap failed!\n");
814+
return -ENOMEM;
815+
}
812816

813817
/* Merge intrigue bits into Runway STATUS 0 */
814818
tmp64 = __raw_readq(runway + RUNWAY_STATUS) & 0xffecfffffffffffful;
815-
__raw_writeq(tmp64 | (*memaddr++ & 0x0013000000000000ul),
819+
__raw_writeq(tmp64 | (*memaddr++ & 0x0013000000000000ul),
816820
runway + RUNWAY_STATUS);
817-
821+
818822
/* Write RUNWAY DEBUG registers */
819823
for (i = 0; i < 8; i++) {
820824
__raw_writeq(*memaddr++, runway + RUNWAY_DEBUG);
821825
}
822826

823-
return 0;
827+
return 0;
824828
}
825829

826830
/*
@@ -844,7 +848,7 @@ printk("perf_rdr_write\n");
844848
perf_rdr_shift_out_U(rdr_num, buffer[i]);
845849
} else {
846850
perf_rdr_shift_out_W(rdr_num, buffer[i]);
847-
}
851+
}
848852
}
849853
printk("perf_rdr_write done\n");
850854
}

0 commit comments

Comments
 (0)