From 5cd5e6ad0ede862432e1e766bfe02a9ad447533e Mon Sep 17 00:00:00 2001 From: Matthias Kaehlcke Date: Mon, 13 Mar 2017 11:57:25 -0700 Subject: hpet: Make cmd parameter of hpet_ioctl_common() unsigned The value passed by the two callers of the function is unsigned anyway. Making the parameter unsigned fixes the following warning when building with clang: drivers/char/hpet.c:588:7: error: overflow converting case value to switch condition type (2149083139 to 18446744071563667459) [-Werror,-Wswitch] case HPET_INFO: ^ include/uapi/linux/hpet.h:18:19: note: expanded from macro 'HPET_INFO' ^ include/uapi/asm-generic/ioctl.h:77:28: note: expanded from macro '_IOR' ^ include/uapi/asm-generic/ioctl.h:66:2: note: expanded from macro '_IOC' (((dir) << _IOC_DIRSHIFT) | \ Signed-off-by: Matthias Kaehlcke Acked-by: Clemens Ladisch Signed-off-by: Greg Kroah-Hartman --- drivers/char/hpet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/char') diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c index 8bdc38d81adf..b941e6d59fd6 100644 --- a/drivers/char/hpet.c +++ b/drivers/char/hpet.c @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets, } static int -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg, struct hpet_info *info) { struct hpet_timer __iomem *timer; -- cgit From 2eec10807a2fbf0f240c55070b71b8cd5c09ab23 Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Thu, 16 Feb 2017 23:11:26 -0800 Subject: drivers/char: Convert remaining use of pr_warning to pr_warn To enable eventual removal of pr_warning This makes pr_warn use consistent for drivers/char Prior to this patch, there were 1 use of pr_warning and 40 uses of pr_warn in drivers/char Signed-off-by: Joe Perches Reviewed-by: Amit Shah Signed-off-by: Greg Kroah-Hartman --- drivers/char/virtio_console.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/char') diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index e9b7e0b3cabe..c6f760b3d9d7 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -2302,7 +2302,7 @@ static int __init init(void) pdrvdata.debugfs_dir = debugfs_create_dir("virtio-ports", NULL); if (!pdrvdata.debugfs_dir) - pr_warning("Error creating debugfs dir for virtio-ports\n"); + pr_warn("Error creating debugfs dir for virtio-ports\n"); INIT_LIST_HEAD(&pdrvdata.consoles); INIT_LIST_HEAD(&pdrvdata.portdevs); -- cgit From 8dbbf582518190b22681c0fa0d9a129b047138a2 Mon Sep 17 00:00:00 2001 From: Logan Gunthorpe Date: Fri, 17 Mar 2017 12:48:13 -0600 Subject: tpm-chip: utilize new cdev_device_add helper function Replace the open coded registration of the cdev and dev with the new device_add_cdev() helper. The helper replaces a common pattern by taking the proper reference against the parent device and adding both the cdev and the device. Signed-off-by: Logan Gunthorpe Reviewed-by: Jason Gunthorpe Reviewed-by: Jarkko Sakkinen Signed-off-by: Greg Kroah-Hartman --- drivers/char/tpm/tpm-chip.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index c406343848da..935f0e92ad61 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -187,7 +187,6 @@ struct tpm_chip *tpm_chip_alloc(struct device *pdev, cdev_init(&chip->cdev, &tpm_fops); chip->cdev.owner = THIS_MODULE; - chip->cdev.kobj.parent = &chip->dev.kobj; return chip; @@ -230,27 +229,16 @@ static int tpm_add_char_device(struct tpm_chip *chip) { int rc; - rc = cdev_add(&chip->cdev, chip->dev.devt, 1); + rc = cdev_device_add(&chip->cdev, &chip->dev); if (rc) { dev_err(&chip->dev, - "unable to cdev_add() %s, major %d, minor %d, err=%d\n", + "unable to cdev_device_add() %s, major %d, minor %d, err=%d\n", dev_name(&chip->dev), MAJOR(chip->dev.devt), MINOR(chip->dev.devt), rc); return rc; } - rc = device_add(&chip->dev); - if (rc) { - dev_err(&chip->dev, - "unable to device_register() %s, major %d, minor %d, err=%d\n", - dev_name(&chip->dev), MAJOR(chip->dev.devt), - MINOR(chip->dev.devt), rc); - - cdev_del(&chip->cdev); - return rc; - } - /* Make the chip available. */ mutex_lock(&idr_lock); idr_replace(&dev_nums_idr, chip, chip->dev_num); @@ -261,8 +249,7 @@ static int tpm_add_char_device(struct tpm_chip *chip) static void tpm_del_char_device(struct tpm_chip *chip) { - cdev_del(&chip->cdev); - device_del(&chip->dev); + cdev_device_del(&chip->cdev, &chip->dev); /* Make the chip unavailable. */ mutex_lock(&idr_lock); -- cgit From f7d88d24c5a2b66b02770e2776fce72b5fd70193 Mon Sep 17 00:00:00 2001 From: Elena Reshetova Date: Mon, 6 Mar 2017 16:20:50 +0200 Subject: drivers, char: convert vma_data.refcnt from atomic_t to refcount_t refcount_t type and corresponding API should be used instead of atomic_t when the variable is used as a reference counter. This allows to avoid accidental refcounter overflows that might lead to use-after-free situations. Signed-off-by: Elena Reshetova Signed-off-by: Hans Liljestrand Signed-off-by: Kees Cook Signed-off-by: David Windsor Signed-off-by: Greg Kroah-Hartman --- drivers/char/mspec.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/mspec.c b/drivers/char/mspec.c index a9c2fa3c81e5..7b75669d3670 100644 --- a/drivers/char/mspec.c +++ b/drivers/char/mspec.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -89,7 +90,7 @@ static int is_sn2; * protect in fork case where multiple tasks share the vma_data. */ struct vma_data { - atomic_t refcnt; /* Number of vmas sharing the data. */ + refcount_t refcnt; /* Number of vmas sharing the data. */ spinlock_t lock; /* Serialize access to this structure. */ int count; /* Number of pages allocated. */ enum mspec_page_type type; /* Type of pages allocated. */ @@ -144,7 +145,7 @@ mspec_open(struct vm_area_struct *vma) struct vma_data *vdata; vdata = vma->vm_private_data; - atomic_inc(&vdata->refcnt); + refcount_inc(&vdata->refcnt); } /* @@ -162,7 +163,7 @@ mspec_close(struct vm_area_struct *vma) vdata = vma->vm_private_data; - if (!atomic_dec_and_test(&vdata->refcnt)) + if (!refcount_dec_and_test(&vdata->refcnt)) return; last_index = (vdata->vm_end - vdata->vm_start) >> PAGE_SHIFT; @@ -274,7 +275,7 @@ mspec_mmap(struct file *file, struct vm_area_struct *vma, vdata->vm_end = vma->vm_end; vdata->type = type; spin_lock_init(&vdata->lock); - atomic_set(&vdata->refcnt, 1); + refcount_set(&vdata->refcnt, 1); vma->vm_private_data = vdata; vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP; -- cgit From 65ebd3dfe79553b294f893ad2b6f54f8b8680e44 Mon Sep 17 00:00:00 2001 From: Varsha Rao Date: Fri, 7 Apr 2017 16:58:54 +0530 Subject: drivers: char: misc: Replace "foo * bar" with "foo *bar". Remove space after * in pointer type, to follow linux coding style. This patch fixes the following checkpatch issue: ERROR: "foo * bar" should be "foo *bar" Signed-off-by: Varsha Rao Signed-off-by: Greg Kroah-Hartman --- drivers/char/misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/misc.c b/drivers/char/misc.c index 8069b361b8dd..ed8f79c630e7 100644 --- a/drivers/char/misc.c +++ b/drivers/char/misc.c @@ -109,7 +109,7 @@ static const struct file_operations misc_proc_fops = { }; #endif -static int misc_open(struct inode * inode, struct file * file) +static int misc_open(struct inode *inode, struct file *file) { int minor = iminor(inode); struct miscdevice *c; @@ -182,7 +182,7 @@ static const struct file_operations misc_fops = { * failure. */ -int misc_register(struct miscdevice * misc) +int misc_register(struct miscdevice *misc) { dev_t dev; int err = 0; -- cgit From 50a5e314792a4edbd64b1156ad4112480189a8dd Mon Sep 17 00:00:00 2001 From: Varsha Rao Date: Fri, 7 Apr 2017 17:01:31 +0530 Subject: drivers: char: misc: Add space after ','. Add space which is required after ',' to follow linux coding style. This patch fixes the checkpatch issue. Signed-off-by: Varsha Rao Signed-off-by: Greg Kroah-Hartman --- drivers/char/misc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/misc.c b/drivers/char/misc.c index ed8f79c630e7..3a19fa3269ff 100644 --- a/drivers/char/misc.c +++ b/drivers/char/misc.c @@ -150,7 +150,7 @@ static int misc_open(struct inode *inode, struct file *file) err = 0; replace_fops(file, new_fops); if (file->f_op->open) - err = file->f_op->open(inode,file); + err = file->f_op->open(inode, file); fail: mutex_unlock(&misc_mtx); return err; @@ -287,7 +287,7 @@ static int __init misc_init(void) goto fail_remove; err = -EIO; - if (register_chrdev(MISC_MAJOR,"misc",&misc_fops)) + if (register_chrdev(MISC_MAJOR, "misc", &misc_fops)) goto fail_printk; misc_class->devnode = misc_devnode; return 0; -- cgit From 5b884a95a5561c9ccea7b5cdf6a2fe9b48b589f5 Mon Sep 17 00:00:00 2001 From: Varsha Rao Date: Fri, 7 Apr 2017 17:02:32 +0530 Subject: drivers: char: misc: Add blank line after declaration. Add a blank line after declaration, to fix the checkpatch issue. Signed-off-by: Varsha Rao Signed-off-by: Greg Kroah-Hartman --- drivers/char/misc.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/char') diff --git a/drivers/char/misc.c b/drivers/char/misc.c index 3a19fa3269ff..1312e29deb00 100644 --- a/drivers/char/misc.c +++ b/drivers/char/misc.c @@ -194,6 +194,7 @@ int misc_register(struct miscdevice *misc) if (is_dynamic) { int i = find_first_zero_bit(misc_minors, DYNAMIC_MINORS); + if (i >= DYNAMIC_MINORS) { err = -EBUSY; goto out; -- cgit From 8ab44b4003381cf4bae7ccdfe81059aa9ce76033 Mon Sep 17 00:00:00 2001 From: Varsha Rao Date: Fri, 7 Apr 2017 17:04:06 +0530 Subject: drivers: char: misc: Replace printk with pr_err. Replace printk with pr_err to fix the checkpatch issue. Signed-off-by: Varsha Rao Signed-off-by: Greg Kroah-Hartman --- drivers/char/misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/char') diff --git a/drivers/char/misc.c b/drivers/char/misc.c index 1312e29deb00..c9cd1ea6844a 100644 --- a/drivers/char/misc.c +++ b/drivers/char/misc.c @@ -294,7 +294,7 @@ static int __init misc_init(void) return 0; fail_printk: - printk("unable to get major %d for misc devices\n", MISC_MAJOR); + pr_err("unable to get major %d for misc devices\n", MISC_MAJOR); class_destroy(misc_class); fail_remove: if (ret) -- cgit From 8b932edfb8788862f10434c1018ad8a6078e0115 Mon Sep 17 00:00:00 2001 From: Shile Zhang Date: Fri, 24 Mar 2017 05:41:04 +0800 Subject: hangcheck-timer: Fix typo in comment Fix the typo "alloted" -> "allotted" in comment. Signed-off-by: Shile Zhang Signed-off-by: Greg Kroah-Hartman --- drivers/char/hangcheck-timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/char') diff --git a/drivers/char/hangcheck-timer.c b/drivers/char/hangcheck-timer.c index 4f337375252e..5406b90bf626 100644 --- a/drivers/char/hangcheck-timer.c +++ b/drivers/char/hangcheck-timer.c @@ -32,7 +32,7 @@ * timer and 180 seconds for the margin of error. IOW, a timer is set * for 60 seconds. When the timer fires, the callback checks the * actual duration that the timer waited. If the duration exceeds the - * alloted time and margin (here 60 + 180, or 240 seconds), the machine + * allotted time and margin (here 60 + 180, or 240 seconds), the machine * is restarted. A healthy machine will have the duration match the * expected timeout very closely. */ -- cgit