aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/checkpatch.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-xscripts/checkpatch.pl78
1 files changed, 73 insertions, 5 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 3257d3d9676..a4d74344d80 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -145,11 +145,14 @@ our $Sparse = qr{
145 __kprobes| 145 __kprobes|
146 __ref 146 __ref
147 }x; 147 }x;
148
149# Notes to $Attribute:
150# We need \b after 'init' otherwise 'initconst' will cause a false positive in a check
148our $Attribute = qr{ 151our $Attribute = qr{
149 const| 152 const|
150 __read_mostly| 153 __read_mostly|
151 __kprobes| 154 __kprobes|
152 __(?:mem|cpu|dev|)(?:initdata|init)| 155 __(?:mem|cpu|dev|)(?:initdata|initconst|init\b)|
153 ____cacheline_aligned| 156 ____cacheline_aligned|
154 ____cacheline_aligned_in_smp| 157 ____cacheline_aligned_in_smp|
155 ____cacheline_internodealigned_in_smp| 158 ____cacheline_internodealigned_in_smp|
@@ -189,6 +192,14 @@ our $typeTypedefs = qr{(?x:
189 atomic_t 192 atomic_t
190)}; 193)};
191 194
195our $logFunctions = qr{(?x:
196 printk|
197 pr_(debug|dbg|vdbg|devel|info|warning|err|notice|alert|crit|emerg|cont)|
198 dev_(printk|dbg|vdbg|info|warn|err|notice|alert|crit|emerg|WARN)|
199 WARN|
200 panic
201)};
202
192our @typeList = ( 203our @typeList = (
193 qr{void}, 204 qr{void},
194 qr{(?:unsigned\s+)?char}, 205 qr{(?:unsigned\s+)?char},
@@ -1377,12 +1388,17 @@ sub process {
1377#80 column limit 1388#80 column limit
1378 if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ && 1389 if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ &&
1379 $rawline !~ /^.\s*\*\s*\@$Ident\s/ && 1390 $rawline !~ /^.\s*\*\s*\@$Ident\s/ &&
1380 $line !~ /^\+\s*printk\s*\(\s*(?:KERN_\S+\s*)?"[X\t]*"\s*(?:,|\)\s*;)\s*$/ && 1391 $line !~ /^\+\s*$logFunctions\s*\(\s*(?:KERN_\S+\s*)?"[X\t]*"\s*(?:,|\)\s*;)\s*$/ &&
1381 $length > 80) 1392 $length > 80)
1382 { 1393 {
1383 WARN("line over 80 characters\n" . $herecurr); 1394 WARN("line over 80 characters\n" . $herecurr);
1384 } 1395 }
1385 1396
1397# check for spaces before a quoted newline
1398 if ($rawline =~ /^.*\".*\s\\n/) {
1399 WARN("unnecessary whitespace before a quoted newline\n" . $herecurr);
1400 }
1401
1386# check for adding lines without a newline. 1402# check for adding lines without a newline.
1387 if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) { 1403 if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) {
1388 WARN("adding a line without newline at end of file\n" . $herecurr); 1404 WARN("adding a line without newline at end of file\n" . $herecurr);
@@ -1411,6 +1427,12 @@ sub process {
1411 ERROR("code indent should use tabs where possible\n" . $herevet); 1427 ERROR("code indent should use tabs where possible\n" . $herevet);
1412 } 1428 }
1413 1429
1430# check for space before tabs.
1431 if ($rawline =~ /^\+/ && $rawline =~ / \t/) {
1432 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1433 WARN("please, no space before tabs\n" . $herevet);
1434 }
1435
1414# check we are in a valid C source file if not then ignore this hunk 1436# check we are in a valid C source file if not then ignore this hunk
1415 next if ($realfile !~ /\.(h|c)$/); 1437 next if ($realfile !~ /\.(h|c)$/);
1416 1438
@@ -2182,8 +2204,10 @@ sub process {
2182 # Find out how long the conditional actually is. 2204 # Find out how long the conditional actually is.
2183 my @newlines = ($c =~ /\n/gs); 2205 my @newlines = ($c =~ /\n/gs);
2184 my $cond_lines = 1 + $#newlines; 2206 my $cond_lines = 1 + $#newlines;
2207 my $stat_real = '';
2185 2208
2186 my $stat_real = raw_line($linenr, $cond_lines); 2209 $stat_real = raw_line($linenr, $cond_lines)
2210 . "\n" if ($cond_lines);
2187 if (defined($stat_real) && $cond_lines > 1) { 2211 if (defined($stat_real) && $cond_lines > 1) {
2188 $stat_real = "[...]\n$stat_real"; 2212 $stat_real = "[...]\n$stat_real";
2189 } 2213 }
@@ -2348,6 +2372,8 @@ sub process {
2348 DECLARE_PER_CPU| 2372 DECLARE_PER_CPU|
2349 DEFINE_PER_CPU| 2373 DEFINE_PER_CPU|
2350 __typeof__\(| 2374 __typeof__\(|
2375 union|
2376 struct|
2351 \.$Ident\s*=\s*| 2377 \.$Ident\s*=\s*|
2352 ^\"|\"$ 2378 ^\"|\"$
2353 }x; 2379 }x;
@@ -2572,6 +2598,11 @@ sub process {
2572 WARN("plain inline is preferred over $1\n" . $herecurr); 2598 WARN("plain inline is preferred over $1\n" . $herecurr);
2573 } 2599 }
2574 2600
2601# check for sizeof(&)
2602 if ($line =~ /\bsizeof\s*\(\s*\&/) {
2603 WARN("sizeof(& should be avoided\n" . $herecurr);
2604 }
2605
2575# check for new externs in .c files. 2606# check for new externs in .c files.
2576 if ($realfile =~ /\.c$/ && defined $stat && 2607 if ($realfile =~ /\.c$/ && defined $stat &&
2577 $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s) 2608 $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
@@ -2634,9 +2665,46 @@ sub process {
2634 if ($line =~ /^.\s*__initcall\s*\(/) { 2665 if ($line =~ /^.\s*__initcall\s*\(/) {
2635 WARN("please use device_initcall() instead of __initcall()\n" . $herecurr); 2666 WARN("please use device_initcall() instead of __initcall()\n" . $herecurr);
2636 } 2667 }
2637# check for struct file_operations, ensure they are const. 2668# check for various ops structs, ensure they are const.
2669 my $struct_ops = qr{acpi_dock_ops|
2670 address_space_operations|
2671 backlight_ops|
2672 block_device_operations|
2673 dentry_operations|
2674 dev_pm_ops|
2675 dma_map_ops|
2676 extent_io_ops|
2677 file_lock_operations|
2678 file_operations|
2679 hv_ops|
2680 ide_dma_ops|
2681 intel_dvo_dev_ops|
2682 item_operations|
2683 iwl_ops|
2684 kgdb_arch|
2685 kgdb_io|
2686 kset_uevent_ops|
2687 lock_manager_operations|
2688 microcode_ops|
2689 mtrr_ops|
2690 neigh_ops|
2691 nlmsvc_binding|
2692 pci_raw_ops|
2693 pipe_buf_operations|
2694 platform_hibernation_ops|
2695 platform_suspend_ops|
2696 proto_ops|
2697 rpc_pipe_ops|
2698 seq_operations|
2699 snd_ac97_build_ops|
2700 soc_pcmcia_socket_ops|
2701 stacktrace_ops|
2702 sysfs_ops|
2703 tty_operations|
2704 usb_mon_operations|
2705 wd_ops}x;
2638 if ($line !~ /\bconst\b/ && 2706 if ($line !~ /\bconst\b/ &&
2639 $line =~ /\bstruct\s+(file_operations|seq_operations)\b/) { 2707 $line =~ /\bstruct\s+($struct_ops)\b/) {
2640 WARN("struct $1 should normally be const\n" . 2708 WARN("struct $1 should normally be const\n" .
2641 $herecurr); 2709 $herecurr);
2642 } 2710 }
div>
316
317
318
319
320













                                                                
                       








                                      

                                         



                                                                    






                                   



                                                               

                                               









                                                                             
                                                            
 

                                                                               

                
                                       










                                                                           
                                         



                   
                                                           
 

                                                                               

                
                                       










                                                                           
                                         



                   
                                                           
 

                                                                               


                
                                       
 



                                                                       



                         



















                                                                               
                                         



                   

                                                                  
 


                                                                               
 



                                                         
                               
 








                                                                           

         

                                   
                   

 
                                                     



                                                                             
                                                   
                             



                                              

  
                                                         
 
                                                                  

                                            


                                               











                                                                            

                                                                    












                                                                              
                                                    

                                                      










                                                                
















                                                                             


                                                                              



                                                                              
                                         

                         
                                                                      















                                                                             
                                                          
                       

                                                                               


                              

                                                 


                 

                                                    



                   
                                                          
 


                                                                             
 

                                                    





                                                   
                                    




                                          
                                          




                                         
/*
 * Watchdog driver for the wm831x PMICs
 *
 * Copyright (C) 2009 Wolfson Microelectronics
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation
 */

#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/platform_device.h>
#include <linux/watchdog.h>
#include <linux/uaccess.h>
#include <linux/gpio.h>

#include <linux/mfd/wm831x/core.h>
#include <linux/mfd/wm831x/pdata.h>
#include <linux/mfd/wm831x/watchdog.h>

static bool nowayout = WATCHDOG_NOWAYOUT;
module_param(nowayout, bool, 0);
MODULE_PARM_DESC(nowayout,
		 "Watchdog cannot be stopped once started (default="
		 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");

struct wm831x_wdt_drvdata {
	struct watchdog_device wdt;
	struct wm831x *wm831x;
	struct mutex lock;
	int update_gpio;
	int update_state;
};

/* We can't use the sub-second values here but they're included
 * for completeness.  */
static struct {
	unsigned int time;  /* Seconds */
	u16 val;            /* WDOG_TO value */
} wm831x_wdt_cfgs[] = {
	{  1, 2 },
	{  2, 3 },
	{  4, 4 },
	{  8, 5 },
	{ 16, 6 },
	{ 32, 7 },
	{ 33, 7 },  /* Actually 32.768s so include both, others round down */
};

static int wm831x_wdt_start(struct watchdog_device *wdt_dev)
{
	struct wm831x_wdt_drvdata *driver_data = watchdog_get_drvdata(wdt_dev);
	struct wm831x *wm831x = driver_data->wm831x;
	int ret;

	mutex_lock(&driver_data->lock);

	ret = wm831x_reg_unlock(wm831x);
	if (ret == 0) {
		ret = wm831x_set_bits(wm831x, WM831X_WATCHDOG,
				      WM831X_WDOG_ENA, WM831X_WDOG_ENA);
		wm831x_reg_lock(wm831x);
	} else {
		dev_err(wm831x->dev, "Failed to unlock security key: %d\n",
			ret);
	}

	mutex_unlock(&driver_data->lock);

	return ret;
}

static int wm831x_wdt_stop(struct watchdog_device *wdt_dev)
{
	struct wm831x_wdt_drvdata *driver_data = watchdog_get_drvdata(wdt_dev);
	struct wm831x *wm831x = driver_data->wm831x;
	int ret;

	mutex_lock(&driver_data->lock);

	ret = wm831x_reg_unlock(wm831x);
	if (ret == 0) {
		ret = wm831x_set_bits(wm831x, WM831X_WATCHDOG,
				      WM831X_WDOG_ENA, 0);
		wm831x_reg_lock(wm831x);
	} else {
		dev_err(wm831x->dev, "Failed to unlock security key: %d\n",
			ret);
	}

	mutex_unlock(&driver_data->lock);

	return ret;
}

static int wm831x_wdt_ping(struct watchdog_device *wdt_dev)
{
	struct wm831x_wdt_drvdata *driver_data = watchdog_get_drvdata(wdt_dev);
	struct wm831x *wm831x = driver_data->wm831x;
	int ret;
	u16 reg;

	mutex_lock(&driver_data->lock);

	if (driver_data->update_gpio) {
		gpio_set_value_cansleep(driver_data->update_gpio,
					driver_data->update_state);
		driver_data->update_state = !driver_data->update_state;
		ret = 0;
		goto out;
	}

	reg = wm831x_reg_read(wm831x, WM831X_WATCHDOG);

	if (!(reg & WM831X_WDOG_RST_SRC)) {
		dev_err(wm831x->dev, "Hardware watchdog update unsupported\n");
		ret = -EINVAL;
		goto out;
	}

	reg |= WM831X_WDOG_RESET;

	ret = wm831x_reg_unlock(wm831x);
	if (ret == 0) {
		ret = wm831x_reg_write(wm831x, WM831X_WATCHDOG, reg);
		wm831x_reg_lock(wm831x);
	} else {
		dev_err(wm831x->dev, "Failed to unlock security key: %d\n",
			ret);
	}

out:
	mutex_unlock(&driver_data->lock);

	return ret;
}

static int wm831x_wdt_set_timeout(struct watchdog_device *wdt_dev,
				  unsigned int timeout)
{
	struct wm831x_wdt_drvdata *driver_data = watchdog_get_drvdata(wdt_dev);
	struct wm831x *wm831x = driver_data->wm831x;
	int ret, i;

	for (i = 0; i < ARRAY_SIZE(wm831x_wdt_cfgs); i++)
		if (wm831x_wdt_cfgs[i].time == timeout)
			break;
	if (i == ARRAY_SIZE(wm831x_wdt_cfgs))
		return -EINVAL;

	ret = wm831x_reg_unlock(wm831x);
	if (ret == 0) {
		ret = wm831x_set_bits(wm831x, WM831X_WATCHDOG,
				      WM831X_WDOG_TO_MASK,
				      wm831x_wdt_cfgs[i].val);
		wm831x_reg_lock(wm831x);
	} else {
		dev_err(wm831x->dev, "Failed to unlock security key: %d\n",
			ret);
	}

	wdt_dev->timeout = timeout;

	return ret;
}

static const struct watchdog_info wm831x_wdt_info = {
	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
	.identity = "WM831x Watchdog",
};

static const struct watchdog_ops wm831x_wdt_ops = {
	.owner = THIS_MODULE,
	.start = wm831x_wdt_start,
	.stop = wm831x_wdt_stop,
	.ping = wm831x_wdt_ping,
	.set_timeout = wm831x_wdt_set_timeout,
};

static int wm831x_wdt_probe(struct platform_device *pdev)
{
	struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
	struct wm831x_pdata *chip_pdata;
	struct wm831x_watchdog_pdata *pdata;
	struct wm831x_wdt_drvdata *driver_data;
	struct watchdog_device *wm831x_wdt;
	int reg, ret, i;

	ret = wm831x_reg_read(wm831x, WM831X_WATCHDOG);
	if (ret < 0) {
		dev_err(wm831x->dev, "Failed to read watchdog status: %d\n",
			ret);
		goto err;
	}
	reg = ret;

	if (reg & WM831X_WDOG_DEBUG)
		dev_warn(wm831x->dev, "Watchdog is paused\n");

	driver_data = devm_kzalloc(&pdev->dev, sizeof(*driver_data),
				   GFP_KERNEL);
	if (!driver_data) {
		dev_err(wm831x->dev, "Unable to alloacate watchdog device\n");
		ret = -ENOMEM;
		goto err;
	}

	mutex_init(&driver_data->lock);
	driver_data->wm831x = wm831x;

	wm831x_wdt = &driver_data->wdt;

	wm831x_wdt->info = &wm831x_wdt_info;
	wm831x_wdt->ops = &wm831x_wdt_ops;
	watchdog_set_nowayout(wm831x_wdt, nowayout);
	watchdog_set_drvdata(wm831x_wdt, driver_data);

	reg = wm831x_reg_read(wm831x, WM831X_WATCHDOG);
	reg &= WM831X_WDOG_TO_MASK;
	for (i = 0; i < ARRAY_SIZE(wm831x_wdt_cfgs); i++)
		if (wm831x_wdt_cfgs[i].val == reg)
			break;
	if (i == ARRAY_SIZE(wm831x_wdt_cfgs))
		dev_warn(wm831x->dev,
			 "Unknown watchdog timeout: %x\n", reg);
	else
		wm831x_wdt->timeout = wm831x_wdt_cfgs[i].time;

	/* Apply any configuration */
	if (pdev->dev.parent->platform_data) {
		chip_pdata = pdev->dev.parent->platform_data;
		pdata = chip_pdata->watchdog;
	} else {
		pdata = NULL;
	}

	if (pdata) {
		reg &= ~(WM831X_WDOG_SECACT_MASK | WM831X_WDOG_PRIMACT_MASK |
			 WM831X_WDOG_RST_SRC);

		reg |= pdata->primary << WM831X_WDOG_PRIMACT_SHIFT;
		reg |= pdata->secondary << WM831X_WDOG_SECACT_SHIFT;
		reg |= pdata->software << WM831X_WDOG_RST_SRC_SHIFT;

		if (pdata->update_gpio) {
			ret = gpio_request_one(pdata->update_gpio,
					       GPIOF_DIR_OUT | GPIOF_INIT_LOW,
					       "Watchdog update");
			if (ret < 0) {
				dev_err(wm831x->dev,
					"Failed to request update GPIO: %d\n",
					ret);
				goto err;
			}

			driver_data->update_gpio = pdata->update_gpio;

			/* Make sure the watchdog takes hardware updates */
			reg |= WM831X_WDOG_RST_SRC;
		}

		ret = wm831x_reg_unlock(wm831x);
		if (ret == 0) {
			ret = wm831x_reg_write(wm831x, WM831X_WATCHDOG, reg);
			wm831x_reg_lock(wm831x);
		} else {
			dev_err(wm831x->dev,
				"Failed to unlock security key: %d\n", ret);
			goto err_gpio;
		}
	}

	ret = watchdog_register_device(&driver_data->wdt);
	if (ret != 0) {
		dev_err(wm831x->dev, "watchdog_register_device() failed: %d\n",
			ret);
		goto err_gpio;
	}

	dev_set_drvdata(&pdev->dev, driver_data);

	return 0;

err_gpio:
	if (driver_data->update_gpio)
		gpio_free(driver_data->update_gpio);
err:
	return ret;
}

static int wm831x_wdt_remove(struct platform_device *pdev)
{
	struct wm831x_wdt_drvdata *driver_data = dev_get_drvdata(&pdev->dev);

	watchdog_unregister_device(&driver_data->wdt);

	if (driver_data->update_gpio)
		gpio_free(driver_data->update_gpio);

	return 0;
}

static struct platform_driver wm831x_wdt_driver = {
	.probe = wm831x_wdt_probe,
	.remove = wm831x_wdt_remove,
	.driver = {
		.name = "wm831x-watchdog",
	},
};

module_platform_driver(wm831x_wdt_driver);

MODULE_AUTHOR("Mark Brown");
MODULE_DESCRIPTION("WM831x Watchdog");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:wm831x-watchdog");