Mauro Carvalho Chehab | b04f2f7 | 2019-04-17 06:46:28 -0300 | [diff] [blame] | 1 | How to Get Your Patch Accepted Into the Hwmon Subsystem |
| 2 | ======================================================= |
Guenter Roeck | c3a2f0a | 2011-04-02 08:26:34 -0700 | [diff] [blame] | 3 | |
Masanari Iida | ac20ad1 | 2013-08-20 05:53:49 -0700 | [diff] [blame] | 4 | This text is a collection of suggestions for people writing patches or |
Guenter Roeck | c3a2f0a | 2011-04-02 08:26:34 -0700 | [diff] [blame] | 5 | drivers for the hwmon subsystem. Following these suggestions will greatly |
| 6 | increase the chances of your change being accepted. |
| 7 | |
| 8 | |
| 9 | 1. General |
| 10 | ---------- |
| 11 | |
Mauro Carvalho Chehab | b04f2f7 | 2019-04-17 06:46:28 -0300 | [diff] [blame] | 12 | * It should be unnecessary to mention, but please read and follow: |
| 13 | |
| 14 | - Documentation/process/submit-checklist.rst |
| 15 | - Documentation/process/submitting-drivers.rst |
| 16 | - Documentation/process/submitting-patches.rst |
| 17 | - Documentation/process/coding-style.rst |
Guenter Roeck | c3a2f0a | 2011-04-02 08:26:34 -0700 | [diff] [blame] | 18 | |
Guenter Roeck | 165720d | 2016-06-10 21:01:28 -0700 | [diff] [blame] | 19 | * Please run your patch through 'checkpatch --strict'. There should be no |
| 20 | errors, no warnings, and few if any check messages. If there are any |
| 21 | messages, please be prepared to explain. |
| 22 | |
Guenter Roeck | 4e19e72 | 2019-09-13 05:43:06 -0700 | [diff] [blame] | 23 | * Please use the standard multi-line comment style. Do not mix C and C++ |
| 24 | style comments in a single driver (with the exception of the SPDX license |
| 25 | identifier). |
| 26 | |
Guenter Roeck | 165720d | 2016-06-10 21:01:28 -0700 | [diff] [blame] | 27 | * If your patch generates checkpatch errors, warnings, or check messages, |
| 28 | please refrain from explanations such as "I prefer that coding style". |
| 29 | Keep in mind that each unnecessary message helps hiding a real problem, |
| 30 | and a consistent coding style makes it easier for others to understand |
| 31 | and review the code. |
Guenter Roeck | c3a2f0a | 2011-04-02 08:26:34 -0700 | [diff] [blame] | 32 | |
| 33 | * Please test your patch thoroughly. We are not your test group. |
| 34 | Sometimes a patch can not or not completely be tested because of missing |
| 35 | hardware. In such cases, you should test-build the code on at least one |
| 36 | architecture. If run-time testing was not achieved, it should be written |
| 37 | explicitly below the patch header. |
| 38 | |
| 39 | * If your patch (or the driver) is affected by configuration options such as |
Stephen Rothwell | 40b3136 | 2013-05-21 13:49:35 +1000 | [diff] [blame] | 40 | CONFIG_SMP, make sure it compiles for all configuration variants. |
Guenter Roeck | c3a2f0a | 2011-04-02 08:26:34 -0700 | [diff] [blame] | 41 | |
| 42 | |
| 43 | 2. Adding functionality to existing drivers |
| 44 | ------------------------------------------- |
| 45 | |
Mauro Carvalho Chehab | 7ebd8b66 | 2019-04-17 06:46:29 -0300 | [diff] [blame] | 46 | * Make sure the documentation in Documentation/hwmon/<driver_name>.rst is up to |
Guenter Roeck | c3a2f0a | 2011-04-02 08:26:34 -0700 | [diff] [blame] | 47 | date. |
| 48 | |
| 49 | * Make sure the information in Kconfig is up to date. |
| 50 | |
| 51 | * If the added functionality requires some cleanup or structural changes, split |
| 52 | your patch into a cleanup part and the actual addition. This makes it easier |
| 53 | to review your changes, and to bisect any resulting problems. |
| 54 | |
| 55 | * Never mix bug fixes, cleanup, and functional enhancements in a single patch. |
| 56 | |
| 57 | |
| 58 | 3. New drivers |
| 59 | -------------- |
| 60 | |
| 61 | * Running your patch or driver file(s) through checkpatch does not mean its |
| 62 | formatting is clean. If unsure about formatting in your new driver, run it |
| 63 | through Lindent. Lindent is not perfect, and you may have to do some minor |
| 64 | cleanup, but it is a good start. |
| 65 | |
| 66 | * Consider adding yourself to MAINTAINERS. |
| 67 | |
Mauro Carvalho Chehab | 7ebd8b66 | 2019-04-17 06:46:29 -0300 | [diff] [blame] | 68 | * Document the driver in Documentation/hwmon/<driver_name>.rst. |
Guenter Roeck | c3a2f0a | 2011-04-02 08:26:34 -0700 | [diff] [blame] | 69 | |
| 70 | * Add the driver to Kconfig and Makefile in alphabetical order. |
| 71 | |
Kees Cook | 07d3360 | 2012-10-02 11:16:18 -0700 | [diff] [blame] | 72 | * Make sure that all dependencies are listed in Kconfig. |
Guenter Roeck | c3a2f0a | 2011-04-02 08:26:34 -0700 | [diff] [blame] | 73 | |
Guenter Roeck | 165720d | 2016-06-10 21:01:28 -0700 | [diff] [blame] | 74 | * Please list include files in alphabetic order. |
| 75 | |
| 76 | * Please align continuation lines with '(' on the previous line. |
| 77 | |
Guenter Roeck | c3a2f0a | 2011-04-02 08:26:34 -0700 | [diff] [blame] | 78 | * Avoid forward declarations if you can. Rearrange the code if necessary. |
| 79 | |
Guenter Roeck | 165720d | 2016-06-10 21:01:28 -0700 | [diff] [blame] | 80 | * Avoid macros to generate groups of sensor attributes. It not only confuses |
| 81 | checkpatch, but also makes it more difficult to review the code. |
| 82 | |
Guenter Roeck | c3a2f0a | 2011-04-02 08:26:34 -0700 | [diff] [blame] | 83 | * Avoid calculations in macros and macro-generated functions. While such macros |
| 84 | may save a line or so in the source, it obfuscates the code and makes code |
| 85 | review more difficult. It may also result in code which is more complicated |
| 86 | than necessary. Use inline functions or just regular functions instead. |
| 87 | |
Guenter Roeck | 165720d | 2016-06-10 21:01:28 -0700 | [diff] [blame] | 88 | * Limit the number of kernel log messages. In general, your driver should not |
| 89 | generate an error message just because a runtime operation failed. Report |
| 90 | errors to user space instead, using an appropriate error code. Keep in mind |
| 91 | that kernel error log messages not only fill up the kernel log, but also are |
| 92 | printed synchronously, most likely with interrupt disabled, often to a serial |
| 93 | console. Excessive logging can seriously affect system performance. |
| 94 | |
Guenter Roeck | 3fafb0c | 2012-06-16 07:33:52 -0700 | [diff] [blame] | 95 | * Use devres functions whenever possible to allocate resources. For rationale |
Mauro Carvalho Chehab | fe34c89 | 2019-06-18 12:34:59 -0300 | [diff] [blame] | 96 | and supported functions, please see Documentation/driver-api/driver-model/devres.rst. |
Guenter Roeck | 165720d | 2016-06-10 21:01:28 -0700 | [diff] [blame] | 97 | If a function is not supported by devres, consider using devm_add_action(). |
Guenter Roeck | 3fafb0c | 2012-06-16 07:33:52 -0700 | [diff] [blame] | 98 | |
Guenter Roeck | c3a2f0a | 2011-04-02 08:26:34 -0700 | [diff] [blame] | 99 | * If the driver has a detect function, make sure it is silent. Debug messages |
| 100 | and messages printed after a successful detection are acceptable, but it |
| 101 | must not print messages such as "Chip XXX not found/supported". |
| 102 | |
| 103 | Keep in mind that the detect function will run for all drivers supporting an |
| 104 | address if a chip is detected on that address. Unnecessary messages will just |
| 105 | pollute the kernel log and not provide any value. |
| 106 | |
| 107 | * Provide a detect function if and only if a chip can be detected reliably. |
| 108 | |
Jean Delvare | 97607f9 | 2015-07-03 14:39:05 +0200 | [diff] [blame] | 109 | * Only the following I2C addresses shall be probed: 0x18-0x1f, 0x28-0x2f, |
| 110 | 0x48-0x4f, 0x58, 0x5c, 0x73 and 0x77. Probing other addresses is strongly |
| 111 | discouraged as it is known to cause trouble with other (non-hwmon) I2C |
| 112 | chips. If your chip lives at an address which can't be probed then the |
| 113 | device will have to be instantiated explicitly (which is always better |
| 114 | anyway.) |
| 115 | |
Guenter Roeck | c3a2f0a | 2011-04-02 08:26:34 -0700 | [diff] [blame] | 116 | * Avoid writing to chip registers in the detect function. If you have to write, |
| 117 | only do it after you have already gathered enough data to be certain that the |
| 118 | detection is going to be successful. |
| 119 | |
| 120 | Keep in mind that the chip might not be what your driver believes it is, and |
| 121 | writing to it might cause a bad misconfiguration. |
| 122 | |
| 123 | * Make sure there are no race conditions in the probe function. Specifically, |
Guenter Roeck | 165720d | 2016-06-10 21:01:28 -0700 | [diff] [blame] | 124 | completely initialize your chip and your driver first, then register with |
| 125 | the hwmon subsystem. |
| 126 | |
Guenter Roeck | 9b0cffa | 2019-09-13 05:06:45 -0700 | [diff] [blame] | 127 | * Use devm_hwmon_device_register_with_info() or, if your driver needs a remove |
| 128 | function, hwmon_device_register_with_info() to register your driver with the |
Guenter Roeck | 165720d | 2016-06-10 21:01:28 -0700 | [diff] [blame] | 129 | hwmon subsystem. Try using devm_add_action() instead of a remove function if |
| 130 | possible. Do not use hwmon_device_register(). |
| 131 | |
| 132 | * Your driver should be buildable as module. If not, please be prepared to |
| 133 | explain why it has to be built into the kernel. |
Guenter Roeck | c3a2f0a | 2011-04-02 08:26:34 -0700 | [diff] [blame] | 134 | |
| 135 | * Do not provide support for deprecated sysfs attributes. |
| 136 | |
| 137 | * Do not create non-standard attributes unless really needed. If you have to use |
| 138 | non-standard attributes, or you believe you do, discuss it on the mailing list |
| 139 | first. Either case, provide a detailed explanation why you need the |
| 140 | non-standard attribute(s). |
Mauro Carvalho Chehab | 7ebd8b66 | 2019-04-17 06:46:29 -0300 | [diff] [blame] | 141 | Standard attributes are specified in Documentation/hwmon/sysfs-interface.rst. |
Guenter Roeck | c3a2f0a | 2011-04-02 08:26:34 -0700 | [diff] [blame] | 142 | |
| 143 | * When deciding which sysfs attributes to support, look at the chip's |
| 144 | capabilities. While we do not expect your driver to support everything the |
| 145 | chip may offer, it should at least support all limits and alarms. |
| 146 | |
| 147 | * Last but not least, please check if a driver for your chip already exists |
| 148 | before starting to write a new driver. Especially for temperature sensors, |
| 149 | new chips are often variants of previously released chips. In some cases, |
| 150 | a presumably new chip may simply have been relabeled. |