submitting-patches.rst 6.7 KB

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