User Tools

Site Tools


en:users:drivers:ath10k:codingstyle

Go back –> ath10k

ath10k Coding Style

Status/error variables

Use a variable named “ret” to store return values or status codes. Also propagate the error code to upper levels.

Example:

int ret;

ret = request_firmware(&fw_entry, filename, ar->dev);
if (ret) {
        ath10k_warn("Failed to request firmware '%s': %d\n",
                    filename, ret);
        return ret;
}

return 0;

Name context variables either “ar” or “ar_<hifname>”. Use ath10k_<hifname>_priv() to get access to hif specific context.

Examples:

struct ath10k *ar = ptr;
struct ath10k_pci *ar_sdio = ath10k_pci_priv(ar);

For consistency always use the main context (struct ath10k *ar) as function parameter, don't use hif specific context.

Error path

Use goto labels err_<action> for handing error path, with <action> giving a clear idea what the label does.

Example:

ret = ath10k_hif_power_on(ar);
if (ret)
        return ret;

ret = ath10k_target_start(ar);
if (ret)
        goto err_power_off;

ret = ath10k_init_upload(ar);
if (ret)
        goto err_target_stop;

return 0;

err_target_stop:
        ath10k_target_stop(ar);

err_power_off:
        ath10k_hif_power_off(ar);

return ret;

Print error codes after a colon:

ath10k_warn("failed to associate peer STA %pM\n: %d",
            sta->addr, ret);

Try to start the warning messages with the the verb “failed” if possible. Warning and error messages start with lower case.

ath10k_warn() is used for errors where it might be possible to recover and ath10k_err() for errors when it's not possible to recover in any way.

Dan Carpenters g+ post about error paths: https://plus.google.com/u/0/106378716002406849458/posts/dnanfhQ4mHQ

Locking

Always document what spinlock/mutex/rcu actually protects. Locks should always protect data, not code flow.

Naming

Name of symbols and functions follow style <drivername>_<filename>_<symbolname>.

Example:

int ath10k_init_hw(struct ath10k *ar)

For each component use function names create/destroy for allocating and freeing something, init/cleanup for initialising variables and cleaning up them afterwards and start/stop to temporarily pause something.

Example:

int ath10k_cfg80211_create(struct ath10k *ar)
int ath10k_cfg80211_start(struct ath10k *ar)
void ath10k_cfg80211_stop(struct ath10k *ar)
void ath10k_cfg80211_destory(struct ath10k *ar)

Comments

Multiline comment style is:

/* Foo
 * Bar
 */

Things NOT to do

Don't use void pointers.

Don't use typedef.

Linux style

Checking code

For checking the code we have a dedicated script ath10k-check which runs various tests, including sparse and checkpatch. Run the script with –help to see the installation and usage instructions. Strongly recommended to run this before submitting patches as it can catch common problems. Example:

~$ cd ~/ath
~/ath$ ls
arch/    debian/         include/  lib/                               Module.symvers  sound/
block/   Documentation/  init/     localversion-wireless-testing      net/            tools/
certs/   drivers/        ipc/      localversion-wireless-testing-ath  README          usr/
COPYING  firmware/       Kbuild    MAINTAINERS                        samples/        virt/
CREDITS  fs/             Kconfig   Makefile                           scripts/        vmlinux-gdb.py@
crypto/  GNUmakefile     kernel/   mm/                                security/
~/ath$ ath10k-check
drivers/net/wireless/ath/ath10k/debug.h:207: return is not a function, parentheses are not required
drivers/net/wireless/ath/ath10k/debug.h:209: return is not a function, parentheses are not required
drivers/net/wireless/ath/ath10k/debug.h:210: return is not a function, parentheses are not required
drivers/net/wireless/ath/ath10k/debug.h:214: Alignment should match open parenthesis
drivers/net/wireless/ath/ath10k/debug.h:218: Alignment should match open parenthesis
drivers/net/wireless/ath/ath10k/debug.c:2430: code indent should use tabs where possible
drivers/net/wireless/ath/ath10k/debug.c:2430: please, no spaces at the start of a line
drivers/net/wireless/ath/ath10k/debug.c:2431: code indent should use tabs where possible
drivers/net/wireless/ath/ath10k/debug.c:2431: please, no spaces at the start of a line
drivers/net/wireless/ath/ath10k/debug.c:2464: code indent should use tabs where possible
drivers/net/wireless/ath/ath10k/debug.c:2464: please, no spaces at the start of a line
drivers/net/wireless/ath/ath10k/debug.c:2465: code indent should use tabs where possible
drivers/net/wireless/ath/ath10k/debug.c:2465: please, no spaces at the start of a line
drivers/net/wireless/ath/ath10k/debug.c:2493: Please don't use multiple blank lines
drivers/net/wireless/ath/ath10k/debug.c:2525: Symbolic permissions 'S_IRUSR' are not preferred. Consider using octal permissions '0400'.
drivers/net/wireless/ath/ath10k/debug.c:2527: Symbolic permissions 'S_IRUSR' are not preferred. Consider using octal permissions '0400'.
drivers/net/wireless/ath/ath10k/debug.c:2620: Alignment should match open parenthesis
drivers/net/wireless/ath/ath10k/debug.c:2640: Alignment should match open parenthesis
~/ath$
en/users/drivers/ath10k/codingstyle.txt · Last modified: 2017/05/12 04:19 by Kalle Valo