pinctrl: intel: Constify struct intel_pinctrl parameter
Subsystems (3)
PATCH 1/1 pinctrl: intel: Constify struct intel_pinctrl parameter
There are a few functions that do not and should not change the state of the pin control object. Constify the respective parameter.
---
There are more opportunities, but they will make the code inconsistent, for example, .get uses const, while .set may not due to locking.
drivers/pinctrl/intel/pinctrl-intel.c | 33 ++++++++++++++------------- drivers/pinctrl/intel/pinctrl-intel.h | 3 ++- 2 files changed, 19 insertions(+), 17 deletions(-)
drivers/pinctrl/intel/pinctrl-intel.c +17 -16
@@ -132,7 +132,8 @@ struct intel_community_context { for_each_intel_pad_group(pctrl, community, grp) \if (grp->gpio_base ==INTEL_GPIO_BASE_NOMAP ) {}else -const struct intel_community *intel_get_community(struct intel_pinctrl *pctrl, unsigned int pin) +const struct intel_community *intel_get_community(const struct intel_pinctrl *pctrl, +unsigned int pin) {const struct intel_community *community;
@@ -161,7 +162,7 @@ intel_community_get_padgroup(const struct intel_community *community,return NULL ; } -static void __iomem *intel_get_padcfg (struct intel_pinctrl *pctrl, +static void __iomem *intel_get_padcfg (const struct intel_pinctrl *pctrl,unsigned int pin,unsigned int reg) {const struct intel_community *community;
@@ -181,7 +182,7 @@ static void __iomem *intel_get_padcfg(struct intel_pinctrl *pctrl,return community->pad_regs + reg + padno * nregs *4 ; } -static bool intel_pad_owned_by_host (struct intel_pinctrl *pctrl,unsigned int pin) +static bool intel_pad_owned_by_host (const struct intel_pinctrl *pctrl,unsigned int pin) {const struct intel_community *community;const struct intel_padgroup *padgrp;
@@ -206,7 +207,7 @@ static bool intel_pad_owned_by_host(struct intel_pinctrl *pctrl, unsigned int pireturn !(readl (padown) &PADOWN_MASK (gpp_offset)); } -static bool intel_pad_acpi_mode (struct intel_pinctrl *pctrl,unsigned int pin) +static bool intel_pad_acpi_mode (const struct intel_pinctrl *pctrl,unsigned int pin) {const struct intel_community *community;const struct intel_padgroup *padgrp;
@@ -248,7 +249,7 @@ enum { PAD_LOCKED_FULL = PAD_LOCKED | PAD_LOCKED_TX, }; -static int intel_pad_locked (struct intel_pinctrl *pctrl,unsigned int pin) +static int intel_pad_locked (const struct intel_pinctrl *pctrl,unsigned int pin) {const struct intel_community *community;const struct intel_padgroup *padgrp;
@@ -286,19 +287,19 @@ static int intel_pad_locked(struct intel_pinctrl *pctrl, unsigned int pin)return ret; } -static bool intel_pad_is_unlocked (struct intel_pinctrl *pctrl,unsigned int pin) +static bool intel_pad_is_unlocked (const struct intel_pinctrl *pctrl,unsigned int pin) {return (intel_pad_locked (pctrl, pin) &PAD_LOCKED ) ==PAD_UNLOCKED ; } -static bool intel_pad_usable (struct intel_pinctrl *pctrl,unsigned int pin) +static bool intel_pad_usable (const struct intel_pinctrl *pctrl,unsigned int pin) {return intel_pad_owned_by_host (pctrl, pin) &&intel_pad_is_unlocked (pctrl, pin); }int intel_get_groups_count (struct pinctrl_dev *pctldev) { -struct intel_pinctrl *pctrl =pinctrl_dev_get_drvdata (pctldev); +const struct intel_pinctrl *pctrl =pinctrl_dev_get_drvdata (pctldev);return pctrl->soc->ngroups; }
@@ -306,7 +307,7 @@ EXPORT_SYMBOL_NS_GPL(intel_get_groups_count, PINCTRL_INTEL);const char *intel_get_group_name (struct pinctrl_dev *pctldev,unsigned int group) { -struct intel_pinctrl *pctrl =pinctrl_dev_get_drvdata (pctldev); +const struct intel_pinctrl *pctrl =pinctrl_dev_get_drvdata (pctldev);return pctrl->soc->groups[group].grp.name; }
@@ -315,7 +316,7 @@ EXPORT_SYMBOL_NS_GPL(intel_get_group_name, PINCTRL_INTEL);int intel_get_group_pins (struct pinctrl_dev *pctldev,unsigned int group,const unsigned int **pins,unsigned int *npins) { -struct intel_pinctrl *pctrl =pinctrl_dev_get_drvdata (pctldev); +const struct intel_pinctrl *pctrl =pinctrl_dev_get_drvdata (pctldev); *pins = pctrl->soc->groups[group].grp.pins; *npins = pctrl->soc->groups[group].grp.npins;
@@ -326,7 +327,7 @@ EXPORT_SYMBOL_NS_GPL(intel_get_group_pins, PINCTRL_INTEL);static void intel_pin_dbg_show (struct pinctrl_dev *pctldev,struct seq_file *s,unsigned int pin) { -struct intel_pinctrl *pctrl =pinctrl_dev_get_drvdata (pctldev); +const struct intel_pinctrl *pctrl =pinctrl_dev_get_drvdata (pctldev);void __iomem *padcfg;u32 cfg0, cfg1, mode;int locked;
@@ -383,7 +384,7 @@ static const struct pinctrl_ops intel_pinctrl_ops = {int intel_get_functions_count (struct pinctrl_dev *pctldev) { -struct intel_pinctrl *pctrl =pinctrl_dev_get_drvdata (pctldev); +const struct intel_pinctrl *pctrl =pinctrl_dev_get_drvdata (pctldev);return pctrl->soc->nfunctions; }
@@ -391,7 +392,7 @@ EXPORT_SYMBOL_NS_GPL(intel_get_functions_count, PINCTRL_INTEL);const char *intel_get_function_name (struct pinctrl_dev *pctldev,unsigned int function) { -struct intel_pinctrl *pctrl =pinctrl_dev_get_drvdata (pctldev); +const struct intel_pinctrl *pctrl =pinctrl_dev_get_drvdata (pctldev);return pctrl->soc->functions[function].func.name; }
@@ -400,7 +401,7 @@ EXPORT_SYMBOL_NS_GPL(intel_get_function_name, PINCTRL_INTEL);int intel_get_function_groups (struct pinctrl_dev *pctldev,unsigned int function,const char *const **groups,unsigned int *const ngroups) { -struct intel_pinctrl *pctrl =pinctrl_dev_get_drvdata (pctldev); +const struct intel_pinctrl *pctrl =pinctrl_dev_get_drvdata (pctldev); *groups = pctrl->soc->functions[function].func.groups; *ngroups = pctrl->soc->functions[function].func.ngroups;
@@ -952,7 +953,7 @@ static const struct pinctrl_desc intel_pinctrl_desc = {* Return: a pin number and pointers to the community and pad group, which * the pin belongs to, or negative error code if translation can't be done. */ -static int intel_gpio_to_pin (struct intel_pinctrl *pctrl,unsigned int offset, +static int intel_gpio_to_pin (const struct intel_pinctrl *pctrl,unsigned int offset,const struct intel_community **community,const struct intel_padgroup **padgrp) {
@@ -982,7 +983,7 @@ static int intel_gpio_to_pin(struct intel_pinctrl *pctrl, unsigned int offset,* * Return: a GPIO offset, or negative error code if translation can't be done. */ -static int intel_pin_to_gpio (struct intel_pinctrl *pctrl,int pin) +static int intel_pin_to_gpio (const struct intel_pinctrl *pctrl,int pin) {const struct intel_community *community;const struct intel_padgroup *padgrp;
drivers/pinctrl/intel/pinctrl-intel.h +2 -1
@@ -264,7 +264,8 @@ int intel_pinctrl_probe_by_uid(struct platform_device *pdev);extern const struct dev_pm_ops intel_pinctrl_pm_ops; -const struct intel_community *intel_get_community (struct intel_pinctrl *pctrl,unsigned int pin); +const struct intel_community *intel_get_community (const struct intel_pinctrl *pctrl, +unsigned int pin);int intel_get_groups_count (struct pinctrl_dev *pctldev);const char *intel_get_group_name (struct pinctrl_dev *pctldev,unsigned int group);
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Mika Westerberg
maintainerdrivers/pinctrl/intel/pinctrl-intel.c intel_community_get_padgroup(const struct intel_community *community, · line 166
Quoted 3 lines · Andy Shevchenko
drivers/pinctrl/intel/pinctrl-intel.c +1
-1-static void __iomem *intel_get_padcfg (struct intel_pinctrl *pctrl, +static void __iomem *intel_get_padcfg (const struct intel_pinctrl *pctrl,unsigned int pin,unsigned int reg)
This is not good. You take const pointer but return non-const inside that struct. I don't think we should "change" the constness this way.
All changes that take const pointer and return scalar are fine, though (did not check all of them).
Quoted 7 lines · Mika Westerberg
drivers/pinctrl/intel/pinctrl-intel.c intel_community_get_padgroup(const struct intel_community *community, · line 166
Quoted 3 lines · Andy Shevchenko
drivers/pinctrl/intel/pinctrl-intel.c +1
-1-static void __iomem *intel_get_padcfg (struct intel_pinctrl *pctrl, +static void __iomem *intel_get_padcfg (const struct intel_pinctrl *pctrl,unsigned int pin,unsigned int reg)This is not good. You take const pointer but return non-const inside that struct. I don't think we should "change" the constness this way.
I see. I will double check this. Thank you for reviewing this!
Quoted 2 lines
All changes that take const pointer and return scalar are fine, though (did not check all of them).
Signature · 2 lines
With Best Regards, Andy Shevchenko