Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cc935bb5 authored by Jonathan Corbet's avatar Jonathan Corbet
Browse files

Merge branch 'doc/4.9' into docs-next

parents d9bd9936 a78a136f
Loading
Loading
Loading
Loading
+19 −9
Original line number Diff line number Diff line
@@ -396,9 +396,13 @@ locations and some common work such as cleanup has to be done. If there is no
cleanup needed then just return directly.

Choose label names which say what the goto does or why the goto exists.  An
example of a good name could be "out_buffer:" if the goto frees "buffer".  Avoid
using GW-BASIC names like "err1:" and "err2:".  Also don't name them after the
goto location like "err_kmalloc_failed:"
example of a good name could be "out_free_buffer:" if the goto frees "buffer".
Avoid using GW-BASIC names like "err1:" and "err2:", as you would have to
renumber them if you ever add or remove exit paths, and they make correctness
difficult to verify anyway.

It is advised to indent labels with a single space (not tab), so that
"diff -p" does not confuse labels with functions.

The rationale for using gotos is:

@@ -425,7 +429,7 @@ The rationale for using gotos is:
			goto out_buffer;
		}
		...
	out_buffer:
	 out_free_buffer:
		kfree(buffer);
		return result;
	}
@@ -438,7 +442,16 @@ A common type of bug to be aware of is "one err bugs" which look like this:
		return ret;

The bug in this code is that on some exit paths "foo" is NULL.  Normally the
fix for this is to split it up into two error labels "err_bar:" and "err_foo:".
fix for this is to split it up into two error labels "err_free_bar:" and
"err_free_foo:":

	 err_free_bar:
		kfree(foo->bar);
	 err_free_foo:
		kfree(foo);
		return ret;

Ideally you should simulate errors to test all exit paths.


		Chapter 8: Commenting
@@ -461,9 +474,6 @@ When commenting the kernel API functions, please use the kernel-doc format.
See the files Documentation/kernel-documentation.rst and scripts/kernel-doc
for details.

Linux style for comments is the C89 "/* ... */" style.
Don't use C99-style "// ..." comments.

The preferred style for long (multi-line) comments is:

	/*
+7 −0
Original line number Diff line number Diff line
@@ -22,9 +22,15 @@ ifeq ($(DOCBOOKS),)
# Skip DocBook build if the user explicitly requested no DOCBOOKS.
.DEFAULT:
	@echo "  SKIP    DocBook $@ target (DOCBOOKS=\"\" specified)."
else
ifneq ($(SPHINXDIRS),)

# Skip DocBook build if the user explicitly requested a sphinx dir
.DEFAULT:
	@echo "  SKIP    DocBook $@ target (SPHINXDIRS specified)."
else


###
# The build process is as follows (targets):
#              (xmldocs) [by docproc]
@@ -221,6 +227,7 @@ silent_gen_xml = :
	   echo "</programlisting>")  > $@

endif # DOCBOOKS=""
endif # SPHINDIR=...

###
# Help targets as used by the top-level makefile
+36 −7
Original line number Diff line number Diff line
@@ -5,6 +5,9 @@
# You can set these variables from the command line.
SPHINXBUILD   = sphinx-build
SPHINXOPTS    =
SPHINXDIRS    = .
_SPHINXDIRS   = $(patsubst $(srctree)/Documentation/%/conf.py,%,$(wildcard $(srctree)/Documentation/*/conf.py))
SPHINX_CONF   = conf.py
PAPER         =
BUILDDIR      = $(obj)/output

@@ -33,30 +36,50 @@ PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
KERNELDOC       = $(srctree)/scripts/kernel-doc
KERNELDOC_CONF  = -D kerneldoc_srctree=$(srctree) -D kerneldoc_bin=$(KERNELDOC)
ALLSPHINXOPTS   = -D version=$(KERNELVERSION) -D release=$(KERNELRELEASE) -d $(BUILDDIR)/.doctrees $(KERNELDOC_CONF) $(PAPEROPT_$(PAPER)) -c $(srctree)/$(src) $(SPHINXOPTS) $(srctree)/$(src)
ALLSPHINXOPTS   =  $(KERNELDOC_CONF) $(PAPEROPT_$(PAPER)) $(SPHINXOPTS)
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS  = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .

quiet_cmd_sphinx = SPHINX  $@
      cmd_sphinx = $(MAKE) BUILDDIR=$(BUILDDIR) $(build)=Documentation/media all; BUILDDIR=$(BUILDDIR) $(SPHINXBUILD) -b $2 $(ALLSPHINXOPTS) $(BUILDDIR)/$2
# commands; the 'cmd' from scripts/Kbuild.include is not *loopable*
loop_cmd = $(echo-cmd) $(cmd_$(1))

# $2 sphinx builder e.g. "html"
# $3 name of the build subfolder / e.g. "media", used as:
#    * dest folder relative to $(BUILDDIR) and
#    * cache folder relative to $(BUILDDIR)/.doctrees
# $4 dest subfolder e.g. "man" for man pages at media/man
# $5 reST source folder relative to $(srctree)/$(src),
#    e.g. "media" for the linux-tv book-set at ./Documentation/media

quiet_cmd_sphinx = SPHINX  $@ --> file://$(abspath $(BUILDDIR)/$3/$4);
      cmd_sphinx = $(MAKE) BUILDDIR=$(abspath $(BUILDDIR)) $(build)=Documentation/media all;\
	BUILDDIR=$(abspath $(BUILDDIR)) SPHINX_CONF=$(abspath $(srctree)/$(src)/$5/$(SPHINX_CONF)) \
	$(SPHINXBUILD) \
	-b $2 \
	-c $(abspath $(srctree)/$(src)) \
	-d $(abspath $(BUILDDIR)/.doctrees/$3) \
	-D version=$(KERNELVERSION) -D release=$(KERNELRELEASE) \
	$(ALLSPHINXOPTS) \
	$(abspath $(srctree)/$(src)/$5) \
	$(abspath $(BUILDDIR)/$3/$4);

htmldocs:
	$(call cmd,sphinx,html)
	@$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,html,$(var),,$(var)))

pdfdocs:
ifeq ($(HAVE_PDFLATEX),0)
	$(warning The 'pdflatex' command was not found. Make sure you have it installed and in PATH to produce PDF output.)
	@echo "  SKIP    Sphinx $@ target."
else # HAVE_PDFLATEX
	$(call cmd,sphinx,latex)
	@$(call loop_cmd,sphinx,latex,.,latex,.))
	$(Q)$(MAKE) -C $(BUILDDIR)/latex
endif # HAVE_PDFLATEX

epubdocs:
	$(call cmd,sphinx,epub)
	@$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,epub,$(var),epub,$(var)))

xmldocs:
	$(call cmd,sphinx,xml)
	@$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,xml,$(var),xml,$(var)))

# no-ops for the Sphinx toolchain
sgmldocs:
@@ -76,3 +99,9 @@ dochelp:
	@echo  '  epubdocs        - EPUB'
	@echo  '  xmldocs         - XML'
	@echo  '  cleandocs       - clean all generated files'
	@echo
	@echo  '  make SPHINXDIRS="s1 s2" [target] Generate only docs of folder s1, s2'
	@echo  '  valid values for SPHINXDIRS are: $(_SPHINXDIRS)'
	@echo
	@echo  '  make SPHINX_CONF={conf-file} [target] use *additional* sphinx-build'
	@echo  '  configuration. This is e.g. useful to build with nit-picking config.'
+22 −20
Original line number Diff line number Diff line
@@ -31,24 +31,25 @@ serve as a convenient shorthand for the implementation of the
hardware-specific bits for the hypothetical "foo" hardware.

Tying the two halves of this interface together is struct clk_hw, which
is defined in struct clk_foo and pointed to within struct clk.  This
is defined in struct clk_foo and pointed to within struct clk_core.  This
allows for easy navigation between the two discrete halves of the common
clock interface.

	Part 2 - common data structures and api

Below is the common struct clk definition from
include/linux/clk-private.h, modified for brevity:
Below is the common struct clk_core definition from
drivers/clk/clk.c, modified for brevity:

	struct clk {
	struct clk_core {
		const char		*name;
		const struct clk_ops	*ops;
		struct clk_hw		*hw;
		char			**parent_names;
		struct clk		**parents;
		struct clk		*parent;
		struct hlist_head	children;
		struct hlist_node	child_node;
		struct module		*owner;
		struct clk_core		*parent;
		const char		**parent_names;
		struct clk_core		**parents;
		u8			num_parents;
		u8			new_parent_index;
		...
	};

@@ -56,16 +57,19 @@ The members above make up the core of the clk tree topology. The clk
api itself defines several driver-facing functions which operate on
struct clk.  That api is documented in include/linux/clk.h.

Platforms and devices utilizing the common struct clk use the struct
clk_ops pointer in struct clk to perform the hardware-specific parts of
the operations defined in clk.h:
Platforms and devices utilizing the common struct clk_core use the struct
clk_ops pointer in struct clk_core to perform the hardware-specific parts of
the operations defined in clk-provider.h:

	struct clk_ops {
		int		(*prepare)(struct clk_hw *hw);
		void		(*unprepare)(struct clk_hw *hw);
		int		(*is_prepared)(struct clk_hw *hw);
		void		(*unprepare_unused)(struct clk_hw *hw);
		int		(*enable)(struct clk_hw *hw);
		void		(*disable)(struct clk_hw *hw);
		int		(*is_enabled)(struct clk_hw *hw);
		void		(*disable_unused)(struct clk_hw *hw);
		unsigned long	(*recalc_rate)(struct clk_hw *hw,
						unsigned long parent_rate);
		long		(*round_rate)(struct clk_hw *hw,
@@ -84,6 +88,8 @@ the operations defined in clk.h:
					    u8 index);
		unsigned long	(*recalc_accuracy)(struct clk_hw *hw,
						unsigned long parent_accuracy);
		int		(*get_phase)(struct clk_hw *hw);
		int		(*set_phase)(struct clk_hw *hw, int degrees);
		void		(*init)(struct clk_hw *hw);
		int		(*debug_init)(struct clk_hw *hw,
					      struct dentry *dentry);
@@ -91,7 +97,7 @@ the operations defined in clk.h:

	Part 3 - hardware clk implementations

The strength of the common struct clk comes from its .ops and .hw pointers
The strength of the common struct clk_core comes from its .ops and .hw pointers
which abstract the details of struct clk from the hardware-specific bits, and
vice versa.  To illustrate consider the simple gateable clk implementation in
drivers/clk/clk-gate.c:
@@ -107,7 +113,7 @@ struct clk_gate contains struct clk_hw hw as well as hardware-specific
knowledge about which register and bit controls this clk's gating.
Nothing about clock topology or accounting, such as enable_count or
notifier_count, is needed here.  That is all handled by the common
framework code and struct clk.
framework code and struct clk_core.

Let's walk through enabling this clk from driver code:

@@ -139,22 +145,18 @@ static void clk_gate_set_bit(struct clk_gate *gate)

Note that to_clk_gate is defined as:

#define to_clk_gate(_hw) container_of(_hw, struct clk_gate, clk)
#define to_clk_gate(_hw) container_of(_hw, struct clk_gate, hw)

This pattern of abstraction is used for every clock hardware
representation.

	Part 4 - supporting your own clk hardware

When implementing support for a new type of clock it only necessary to
When implementing support for a new type of clock it is only necessary to
include the following header:

#include <linux/clk-provider.h>

include/linux/clk.h is included within that header and clk-private.h
must never be included from the code which implements the operations for
a clock.  More on that below in Part 5.

To construct a clk hardware structure for your platform you must define
the following:

+7 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import os
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('sphinx'))
from load_config import loadConfig

# -- General configuration ------------------------------------------------

@@ -421,3 +422,9 @@ pdf_documents = [
# line arguments.
kerneldoc_bin = '../scripts/kernel-doc'
kerneldoc_srctree = '..'

# ------------------------------------------------------------------------------
# Since loadConfig overwrites settings from the global namespace, it has to be
# the last statement in the conf.py file
# ------------------------------------------------------------------------------
loadConfig(globals())
Loading