0001 How to Get Your Patch Accepted Into the Hwmon Subsystem
0002 =======================================================
0003
0004 This text is a collection of suggestions for people writing patches or
0005 drivers for the hwmon subsystem. Following these suggestions will greatly
0006 increase the chances of your change being accepted.
0007
0008
0009 1. General
0010 ----------
0011
0012 * It should be unnecessary to mention, but please read and follow:
0013
0014 - Documentation/process/submit-checklist.rst
0015 - Documentation/process/submitting-patches.rst
0016 - Documentation/process/coding-style.rst
0017
0018 * Please run your patch through 'checkpatch --strict'. There should be no
0019 errors, no warnings, and few if any check messages. If there are any
0020 messages, please be prepared to explain.
0021
0022 * Please use the standard multi-line comment style. Do not mix C and C++
0023 style comments in a single driver (with the exception of the SPDX license
0024 identifier).
0025
0026 * If your patch generates checkpatch errors, warnings, or check messages,
0027 please refrain from explanations such as "I prefer that coding style".
0028 Keep in mind that each unnecessary message helps hiding a real problem,
0029 and a consistent coding style makes it easier for others to understand
0030 and review the code.
0031
0032 * Please test your patch thoroughly. We are not your test group.
0033 Sometimes a patch can not or not completely be tested because of missing
0034 hardware. In such cases, you should test-build the code on at least one
0035 architecture. If run-time testing was not achieved, it should be written
0036 explicitly below the patch header.
0037
0038 * If your patch (or the driver) is affected by configuration options such as
0039 CONFIG_SMP, make sure it compiles for all configuration variants.
0040
0041
0042 2. Adding functionality to existing drivers
0043 -------------------------------------------
0044
0045 * Make sure the documentation in Documentation/hwmon/<driver_name>.rst is up to
0046 date.
0047
0048 * Make sure the information in Kconfig is up to date.
0049
0050 * If the added functionality requires some cleanup or structural changes, split
0051 your patch into a cleanup part and the actual addition. This makes it easier
0052 to review your changes, and to bisect any resulting problems.
0053
0054 * Never mix bug fixes, cleanup, and functional enhancements in a single patch.
0055
0056
0057 3. New drivers
0058 --------------
0059
0060 * Running your patch or driver file(s) through checkpatch does not mean its
0061 formatting is clean. If unsure about formatting in your new driver, run it
0062 through Lindent. Lindent is not perfect, and you may have to do some minor
0063 cleanup, but it is a good start.
0064
0065 * Consider adding yourself to MAINTAINERS.
0066
0067 * Document the driver in Documentation/hwmon/<driver_name>.rst.
0068
0069 * Add the driver to Kconfig and Makefile in alphabetical order.
0070
0071 * Make sure that all dependencies are listed in Kconfig.
0072
0073 * Please list include files in alphabetic order.
0074
0075 * Please align continuation lines with '(' on the previous line.
0076
0077 * Avoid forward declarations if you can. Rearrange the code if necessary.
0078
0079 * Avoid macros to generate groups of sensor attributes. It not only confuses
0080 checkpatch, but also makes it more difficult to review the code.
0081
0082 * Avoid calculations in macros and macro-generated functions. While such macros
0083 may save a line or so in the source, it obfuscates the code and makes code
0084 review more difficult. It may also result in code which is more complicated
0085 than necessary. Use inline functions or just regular functions instead.
0086
0087 * Limit the number of kernel log messages. In general, your driver should not
0088 generate an error message just because a runtime operation failed. Report
0089 errors to user space instead, using an appropriate error code. Keep in mind
0090 that kernel error log messages not only fill up the kernel log, but also are
0091 printed synchronously, most likely with interrupt disabled, often to a serial
0092 console. Excessive logging can seriously affect system performance.
0093
0094 * Use devres functions whenever possible to allocate resources. For rationale
0095 and supported functions, please see Documentation/driver-api/driver-model/devres.rst.
0096 If a function is not supported by devres, consider using devm_add_action().
0097
0098 * If the driver has a detect function, make sure it is silent. Debug messages
0099 and messages printed after a successful detection are acceptable, but it
0100 must not print messages such as "Chip XXX not found/supported".
0101
0102 Keep in mind that the detect function will run for all drivers supporting an
0103 address if a chip is detected on that address. Unnecessary messages will just
0104 pollute the kernel log and not provide any value.
0105
0106 * Provide a detect function if and only if a chip can be detected reliably.
0107
0108 * Only the following I2C addresses shall be probed: 0x18-0x1f, 0x28-0x2f,
0109 0x48-0x4f, 0x58, 0x5c, 0x73 and 0x77. Probing other addresses is strongly
0110 discouraged as it is known to cause trouble with other (non-hwmon) I2C
0111 chips. If your chip lives at an address which can't be probed then the
0112 device will have to be instantiated explicitly (which is always better
0113 anyway.)
0114
0115 * Avoid writing to chip registers in the detect function. If you have to write,
0116 only do it after you have already gathered enough data to be certain that the
0117 detection is going to be successful.
0118
0119 Keep in mind that the chip might not be what your driver believes it is, and
0120 writing to it might cause a bad misconfiguration.
0121
0122 * Make sure there are no race conditions in the probe function. Specifically,
0123 completely initialize your chip and your driver first, then register with
0124 the hwmon subsystem.
0125
0126 * Use devm_hwmon_device_register_with_info() or, if your driver needs a remove
0127 function, hwmon_device_register_with_info() to register your driver with the
0128 hwmon subsystem. Try using devm_add_action() instead of a remove function if
0129 possible. Do not use hwmon_device_register().
0130
0131 * Your driver should be buildable as module. If not, please be prepared to
0132 explain why it has to be built into the kernel.
0133
0134 * Do not provide support for deprecated sysfs attributes.
0135
0136 * Do not create non-standard attributes unless really needed. If you have to use
0137 non-standard attributes, or you believe you do, discuss it on the mailing list
0138 first. Either case, provide a detailed explanation why you need the
0139 non-standard attribute(s).
0140 Standard attributes are specified in Documentation/hwmon/sysfs-interface.rst.
0141
0142 * When deciding which sysfs attributes to support, look at the chip's
0143 capabilities. While we do not expect your driver to support everything the
0144 chip may offer, it should at least support all limits and alarms.
0145
0146 * Last but not least, please check if a driver for your chip already exists
0147 before starting to write a new driver. Especially for temperature sensors,
0148 new chips are often variants of previously released chips. In some cases,
0149 a presumably new chip may simply have been relabeled.