xref: /openbmc/linux/Documentation/hwmon/submitting-patches.rst (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
17ebd8b66SMauro Carvalho ChehabHow to Get Your Patch Accepted Into the Hwmon Subsystem
27ebd8b66SMauro Carvalho Chehab=======================================================
37ebd8b66SMauro Carvalho Chehab
47ebd8b66SMauro Carvalho ChehabThis text is a collection of suggestions for people writing patches or
57ebd8b66SMauro Carvalho Chehabdrivers for the hwmon subsystem. Following these suggestions will greatly
67ebd8b66SMauro Carvalho Chehabincrease the chances of your change being accepted.
77ebd8b66SMauro Carvalho Chehab
87ebd8b66SMauro Carvalho Chehab
97ebd8b66SMauro Carvalho Chehab1. General
107ebd8b66SMauro Carvalho Chehab----------
117ebd8b66SMauro Carvalho Chehab
127ebd8b66SMauro Carvalho Chehab* It should be unnecessary to mention, but please read and follow:
137ebd8b66SMauro Carvalho Chehab
147ebd8b66SMauro Carvalho Chehab    - Documentation/process/submit-checklist.rst
157ebd8b66SMauro Carvalho Chehab    - Documentation/process/submitting-patches.rst
167ebd8b66SMauro Carvalho Chehab    - Documentation/process/coding-style.rst
177ebd8b66SMauro Carvalho Chehab
187ebd8b66SMauro Carvalho Chehab* Please run your patch through 'checkpatch --strict'. There should be no
197ebd8b66SMauro Carvalho Chehab  errors, no warnings, and few if any check messages. If there are any
207ebd8b66SMauro Carvalho Chehab  messages, please be prepared to explain.
217ebd8b66SMauro Carvalho Chehab
224e19e72fSGuenter Roeck* Please use the standard multi-line comment style. Do not mix C and C++
234e19e72fSGuenter Roeck  style comments in a single driver (with the exception of the SPDX license
244e19e72fSGuenter Roeck  identifier).
254e19e72fSGuenter Roeck
267ebd8b66SMauro Carvalho Chehab* If your patch generates checkpatch errors, warnings, or check messages,
277ebd8b66SMauro Carvalho Chehab  please refrain from explanations such as "I prefer that coding style".
287ebd8b66SMauro Carvalho Chehab  Keep in mind that each unnecessary message helps hiding a real problem,
297ebd8b66SMauro Carvalho Chehab  and a consistent coding style makes it easier for others to understand
307ebd8b66SMauro Carvalho Chehab  and review the code.
317ebd8b66SMauro Carvalho Chehab
327ebd8b66SMauro Carvalho Chehab* Please test your patch thoroughly. We are not your test group.
337ebd8b66SMauro Carvalho Chehab  Sometimes a patch can not or not completely be tested because of missing
347ebd8b66SMauro Carvalho Chehab  hardware. In such cases, you should test-build the code on at least one
357ebd8b66SMauro Carvalho Chehab  architecture. If run-time testing was not achieved, it should be written
367ebd8b66SMauro Carvalho Chehab  explicitly below the patch header.
377ebd8b66SMauro Carvalho Chehab
387ebd8b66SMauro Carvalho Chehab* If your patch (or the driver) is affected by configuration options such as
397ebd8b66SMauro Carvalho Chehab  CONFIG_SMP, make sure it compiles for all configuration variants.
407ebd8b66SMauro Carvalho Chehab
417ebd8b66SMauro Carvalho Chehab
427ebd8b66SMauro Carvalho Chehab2. Adding functionality to existing drivers
437ebd8b66SMauro Carvalho Chehab-------------------------------------------
447ebd8b66SMauro Carvalho Chehab
457ebd8b66SMauro Carvalho Chehab* Make sure the documentation in Documentation/hwmon/<driver_name>.rst is up to
467ebd8b66SMauro Carvalho Chehab  date.
477ebd8b66SMauro Carvalho Chehab
487ebd8b66SMauro Carvalho Chehab* Make sure the information in Kconfig is up to date.
497ebd8b66SMauro Carvalho Chehab
507ebd8b66SMauro Carvalho Chehab* If the added functionality requires some cleanup or structural changes, split
517ebd8b66SMauro Carvalho Chehab  your patch into a cleanup part and the actual addition. This makes it easier
527ebd8b66SMauro Carvalho Chehab  to review your changes, and to bisect any resulting problems.
537ebd8b66SMauro Carvalho Chehab
547ebd8b66SMauro Carvalho Chehab* Never mix bug fixes, cleanup, and functional enhancements in a single patch.
557ebd8b66SMauro Carvalho Chehab
567ebd8b66SMauro Carvalho Chehab
577ebd8b66SMauro Carvalho Chehab3. New drivers
587ebd8b66SMauro Carvalho Chehab--------------
597ebd8b66SMauro Carvalho Chehab
607ebd8b66SMauro Carvalho Chehab* Running your patch or driver file(s) through checkpatch does not mean its
617ebd8b66SMauro Carvalho Chehab  formatting is clean. If unsure about formatting in your new driver, run it
627ebd8b66SMauro Carvalho Chehab  through Lindent. Lindent is not perfect, and you may have to do some minor
637ebd8b66SMauro Carvalho Chehab  cleanup, but it is a good start.
647ebd8b66SMauro Carvalho Chehab
657ebd8b66SMauro Carvalho Chehab* Consider adding yourself to MAINTAINERS.
667ebd8b66SMauro Carvalho Chehab
677ebd8b66SMauro Carvalho Chehab* Document the driver in Documentation/hwmon/<driver_name>.rst.
687ebd8b66SMauro Carvalho Chehab
697ebd8b66SMauro Carvalho Chehab* Add the driver to Kconfig and Makefile in alphabetical order.
707ebd8b66SMauro Carvalho Chehab
717ebd8b66SMauro Carvalho Chehab* Make sure that all dependencies are listed in Kconfig.
727ebd8b66SMauro Carvalho Chehab
737ebd8b66SMauro Carvalho Chehab* Please list include files in alphabetic order.
747ebd8b66SMauro Carvalho Chehab
757ebd8b66SMauro Carvalho Chehab* Please align continuation lines with '(' on the previous line.
767ebd8b66SMauro Carvalho Chehab
777ebd8b66SMauro Carvalho Chehab* Avoid forward declarations if you can. Rearrange the code if necessary.
787ebd8b66SMauro Carvalho Chehab
797ebd8b66SMauro Carvalho Chehab* Avoid macros to generate groups of sensor attributes. It not only confuses
807ebd8b66SMauro Carvalho Chehab  checkpatch, but also makes it more difficult to review the code.
817ebd8b66SMauro Carvalho Chehab
827ebd8b66SMauro Carvalho Chehab* Avoid calculations in macros and macro-generated functions. While such macros
837ebd8b66SMauro Carvalho Chehab  may save a line or so in the source, it obfuscates the code and makes code
847ebd8b66SMauro Carvalho Chehab  review more difficult. It may also result in code which is more complicated
857ebd8b66SMauro Carvalho Chehab  than necessary. Use inline functions or just regular functions instead.
867ebd8b66SMauro Carvalho Chehab
877ebd8b66SMauro Carvalho Chehab* Limit the number of kernel log messages. In general, your driver should not
887ebd8b66SMauro Carvalho Chehab  generate an error message just because a runtime operation failed. Report
897ebd8b66SMauro Carvalho Chehab  errors to user space instead, using an appropriate error code. Keep in mind
907ebd8b66SMauro Carvalho Chehab  that kernel error log messages not only fill up the kernel log, but also are
917ebd8b66SMauro Carvalho Chehab  printed synchronously, most likely with interrupt disabled, often to a serial
927ebd8b66SMauro Carvalho Chehab  console. Excessive logging can seriously affect system performance.
937ebd8b66SMauro Carvalho Chehab
947ebd8b66SMauro Carvalho Chehab* Use devres functions whenever possible to allocate resources. For rationale
95fe34c89dSMauro Carvalho Chehab  and supported functions, please see Documentation/driver-api/driver-model/devres.rst.
967ebd8b66SMauro Carvalho Chehab  If a function is not supported by devres, consider using devm_add_action().
977ebd8b66SMauro Carvalho Chehab
987ebd8b66SMauro Carvalho Chehab* If the driver has a detect function, make sure it is silent. Debug messages
997ebd8b66SMauro Carvalho Chehab  and messages printed after a successful detection are acceptable, but it
1007ebd8b66SMauro Carvalho Chehab  must not print messages such as "Chip XXX not found/supported".
1017ebd8b66SMauro Carvalho Chehab
1027ebd8b66SMauro Carvalho Chehab  Keep in mind that the detect function will run for all drivers supporting an
1037ebd8b66SMauro Carvalho Chehab  address if a chip is detected on that address. Unnecessary messages will just
1047ebd8b66SMauro Carvalho Chehab  pollute the kernel log and not provide any value.
1057ebd8b66SMauro Carvalho Chehab
1067ebd8b66SMauro Carvalho Chehab* Provide a detect function if and only if a chip can be detected reliably.
1077ebd8b66SMauro Carvalho Chehab
1087ebd8b66SMauro Carvalho Chehab* Only the following I2C addresses shall be probed: 0x18-0x1f, 0x28-0x2f,
1097ebd8b66SMauro Carvalho Chehab  0x48-0x4f, 0x58, 0x5c, 0x73 and 0x77. Probing other addresses is strongly
1107ebd8b66SMauro Carvalho Chehab  discouraged as it is known to cause trouble with other (non-hwmon) I2C
1117ebd8b66SMauro Carvalho Chehab  chips. If your chip lives at an address which can't be probed then the
1127ebd8b66SMauro Carvalho Chehab  device will have to be instantiated explicitly (which is always better
1137ebd8b66SMauro Carvalho Chehab  anyway.)
1147ebd8b66SMauro Carvalho Chehab
1157ebd8b66SMauro Carvalho Chehab* Avoid writing to chip registers in the detect function. If you have to write,
1167ebd8b66SMauro Carvalho Chehab  only do it after you have already gathered enough data to be certain that the
1177ebd8b66SMauro Carvalho Chehab  detection is going to be successful.
1187ebd8b66SMauro Carvalho Chehab
1197ebd8b66SMauro Carvalho Chehab  Keep in mind that the chip might not be what your driver believes it is, and
1207ebd8b66SMauro Carvalho Chehab  writing to it might cause a bad misconfiguration.
1217ebd8b66SMauro Carvalho Chehab
1227ebd8b66SMauro Carvalho Chehab* Make sure there are no race conditions in the probe function. Specifically,
1237ebd8b66SMauro Carvalho Chehab  completely initialize your chip and your driver first, then register with
1247ebd8b66SMauro Carvalho Chehab  the hwmon subsystem.
1257ebd8b66SMauro Carvalho Chehab
1269b0cffa6SGuenter Roeck* Use devm_hwmon_device_register_with_info() or, if your driver needs a remove
1279b0cffa6SGuenter Roeck  function, hwmon_device_register_with_info() to register your driver with the
1287ebd8b66SMauro Carvalho Chehab  hwmon subsystem. Try using devm_add_action() instead of a remove function if
129*5720a18bSGuenter Roeck  possible. Do not use any of the deprecated registration functions.
1307ebd8b66SMauro Carvalho Chehab
1317ebd8b66SMauro Carvalho Chehab* Your driver should be buildable as module. If not, please be prepared to
1327ebd8b66SMauro Carvalho Chehab  explain why it has to be built into the kernel.
1337ebd8b66SMauro Carvalho Chehab
1347ebd8b66SMauro Carvalho Chehab* Do not provide support for deprecated sysfs attributes.
1357ebd8b66SMauro Carvalho Chehab
1367ebd8b66SMauro Carvalho Chehab* Do not create non-standard attributes unless really needed. If you have to use
1377ebd8b66SMauro Carvalho Chehab  non-standard attributes, or you believe you do, discuss it on the mailing list
1387ebd8b66SMauro Carvalho Chehab  first. Either case, provide a detailed explanation why you need the
1397ebd8b66SMauro Carvalho Chehab  non-standard attribute(s).
1407ebd8b66SMauro Carvalho Chehab  Standard attributes are specified in Documentation/hwmon/sysfs-interface.rst.
1417ebd8b66SMauro Carvalho Chehab
1427ebd8b66SMauro Carvalho Chehab* When deciding which sysfs attributes to support, look at the chip's
1437ebd8b66SMauro Carvalho Chehab  capabilities. While we do not expect your driver to support everything the
1447ebd8b66SMauro Carvalho Chehab  chip may offer, it should at least support all limits and alarms.
1457ebd8b66SMauro Carvalho Chehab
1467ebd8b66SMauro Carvalho Chehab* Last but not least, please check if a driver for your chip already exists
1477ebd8b66SMauro Carvalho Chehab  before starting to write a new driver. Especially for temperature sensors,
1487ebd8b66SMauro Carvalho Chehab  new chips are often variants of previously released chips. In some cases,
1497ebd8b66SMauro Carvalho Chehab  a presumably new chip may simply have been relabeled.
150