diff --git a/drivers/dpll/dpll_core.c b/drivers/dpll/dpll_core.c index 0b5f499cfc4d5..f56a283ea35de 100644 --- a/drivers/dpll/dpll_core.c +++ b/drivers/dpll/dpll_core.c @@ -190,6 +190,7 @@ void dpll_init_pin(struct dpll_pin **pin, enum dpll_pin_type type, (*pin)->type = type; (*pin)->priv = priv; (*pin)->id = id; + refcount_set(&((*pin)->ref_count), 0); if (name) snprintf((*pin)->name, PIN_NAME_LENGTH, "%s", name); else @@ -241,7 +242,7 @@ int dpll_pin_register(struct dpll_device *dpll, struct dpll_pin *pin) mutex_lock(&dpll->lock); ret = pin_register(&dpll->pins, pin); if (!ret) { - pin->ref_count++; + refcount_inc(&pin->ref_count); change_pin_count(dpll, pin, true); xa_set_mark(&dpll->pins, dpll->id, DPLL_REGISTERED); } @@ -287,9 +288,7 @@ int dpll_pin_deregister(struct dpll_device *dpll, struct dpll_pin *pin) mutex_unlock(&dpll->lock); if (!ret) { - mutex_lock(&pin->lock); - pin->ref_count--; - mutex_unlock(&pin->lock); + refcount_dec(&pin->ref_count); dpll_notify_pin_deregister(dpll->id, pin->id); } @@ -311,7 +310,7 @@ void dpll_pin_free(struct dpll_device *dpll, struct dpll_pin *pin) if (!pin_found) return; - if (pin->ref_count) + if (refcount_read(&pin->ref_count) != 0) return; xa_destroy(&pin->muxed_pins); @@ -333,7 +332,7 @@ void dpll_muxed_pin_free(struct dpll_pin *parent_pin, struct dpll_pin *pin) if (!pin_found) return; - if (pin->ref_count) + if (refcount_read(&pin->ref_count) != 0) return; xa_destroy(&pin->muxed_pins); @@ -348,9 +347,7 @@ int dpll_muxed_pin_register(struct dpll_pin *parent_pin, struct dpll_pin *pin) ret = pin_register(&parent_pin->muxed_pins, pin); if (!ret) { - mutex_lock(&pin->lock); - pin->ref_count++; - mutex_unlock(&pin->lock); + refcount_inc(&pin->ref_count); dpll_notify_muxed_pin_register(parent_pin, pin->id); } @@ -370,9 +367,7 @@ int dpll_muxed_pin_deregister(struct dpll_pin *parent_pin, struct dpll_pin *pin) mutex_unlock(&parent_pin->lock); if (!ret) { - mutex_lock(&pin->lock); - pin->ref_count--; - mutex_unlock(&pin->lock); + refcount_dec(&pin->ref_count); dpll_notify_muxed_pin_deregister(parent_pin, pin->id); } diff --git a/drivers/dpll/dpll_core.h b/drivers/dpll/dpll_core.h index 7ff64df735d93..7db9b23b4a084 100644 --- a/drivers/dpll/dpll_core.h +++ b/drivers/dpll/dpll_core.h @@ -36,7 +36,7 @@ struct dpll_pin { int id; enum dpll_pin_type type; - int ref_count; + refcount_t ref_count; struct dpll_pin_ops *ops; struct mutex lock; void *priv; diff --git a/drivers/dpll/dpll_netlink.c b/drivers/dpll/dpll_netlink.c index 5c43da0b4d7dd..6b081d19cf0f3 100644 --- a/drivers/dpll/dpll_netlink.c +++ b/drivers/dpll/dpll_netlink.c @@ -133,8 +133,8 @@ static int __dpll_cmd_dump_sources(struct dpll_device *dpll, } ret = 0; } - if (pin->ops->get_prio) { - prio = pin->ops->get_prio(pin, dpll); + if (dpll->ops->get_prio) { + prio = dpll->ops->get_prio(dpll, pin); if (nla_put_u32(msg, DPLLA_SOURCE_PIN_PRIO, prio)) { nla_nest_cancel(msg, src_attr); ret = -EMSGSIZE; @@ -393,10 +393,10 @@ static int dpll_genl_cmd_set_source_prio(struct sk_buff *skb, struct genl_info * mutex_lock(&dpll->lock); pin = dpll_pin_get_by_id(dpll, src_id); - if (!pin || !pin->ops || !pin->ops->set_prio) + if (!dpll->ops || !dpll->ops->set_prio) ret = -EOPNOTSUPP; else - ret = pin->ops->set_prio(pin, dpll, prio); + ret = dpll->ops->set_prio(dpll, pin, prio); mutex_unlock(&dpll->lock); if (!ret) diff --git a/drivers/net/ethernet/intel/ice/ice_synce.c b/drivers/net/ethernet/intel/ice/ice_synce.c index 39c1a1be222d7..523bd998c3b7e 100644 --- a/drivers/net/ethernet/intel/ice/ice_synce.c +++ b/drivers/net/ethernet/intel/ice/ice_synce.c @@ -361,13 +361,13 @@ static int ice_synce_get_src_select_supported(struct dpll_device *dpll, int mode /** * ice_synce_get_source_prio * @dpll: registered dpll pointer - * @id: source index + * @pin: dpll pin object * * dpll subsystem callback. * Get source priority value. * Return: source priority value */ -static int ice_synce_get_source_prio(struct dpll_pin *pin, struct dpll_device *dpll) +static int ice_synce_get_source_prio(struct dpll_device *dpll, struct dpll_pin *pin) { struct ice_pf *pf = dpll_priv(dpll); u8 idx = (u8)pin_id(pin); @@ -389,7 +389,7 @@ static int ice_synce_get_source_prio(struct dpll_pin *pin, struct dpll_device *d /** * ice_synce_set_source_prio * @dpll: registered dpll pointer - * @id: source index + * @pin: dpll pin object * @prio: expected priority value * * dpll subsystem callback. @@ -398,8 +398,8 @@ static int ice_synce_get_source_prio(struct dpll_pin *pin, struct dpll_device *d * * 0 - success * * negative - failure */ -static int ice_synce_set_source_prio(struct dpll_pin *pin, - struct dpll_device *dpll, int prio) +static int ice_synce_set_source_prio(struct dpll_device *dpll, + struct dpll_pin *pin, int prio) { struct ice_pf *pf = dpll_priv(dpll); u8 idx, priov = (u8)prio; @@ -435,8 +435,6 @@ static struct dpll_pin_ops ice_synce_source_ops = { .get_type = ice_synce_get_source_type, .set_type = ice_synce_set_source_type, .is_type_supported = ice_synce_get_source_supported, - .get_prio = ice_synce_get_source_prio, - .set_prio = ice_synce_set_source_prio, }; static struct dpll_pin_ops ice_synce_output_ops = { @@ -450,6 +448,8 @@ static struct dpll_device_ops ice_synce_dpll_ops = { .get_lock_status = ice_synce_get_lock_status, .get_source_select_mode = ice_synce_get_source_select_mode, .get_source_select_mode_supported = ice_synce_get_src_select_supported, + .get_prio = ice_synce_get_source_prio, + .set_prio = ice_synce_set_source_prio, }; /** diff --git a/include/linux/dpll.h b/include/linux/dpll.h index 133999be7f066..1e54f56450a0c 100644 --- a/include/linux/dpll.h +++ b/include/linux/dpll.h @@ -22,6 +22,8 @@ struct dpll_device_ops { int (*get_source_supported)(struct dpll_device *dpll, int sma, int type); int (*get_output_type)(struct dpll_device *dpll, int sma); int (*get_output_supported)(struct dpll_device, int sma, int type); + int (*get_prio)(struct dpll_device *dpll, struct dpll_pin *pin); + int (*set_prio)(struct dpll_device *dpll, struct dpll_pin *pin, int prio); }; struct dpll_pin_ops { @@ -30,8 +32,6 @@ struct dpll_pin_ops { int (*set_type)(struct dpll_pin *pin, int type); int (*set_source)(struct dpll_pin *pin, struct dpll_device *dpll, int id); int (*set_flags)(struct dpll_pin *pin, struct dpll_device *dpll, int flags); - int (*get_prio)(struct dpll_pin *pin, struct dpll_device *dpll); - int (*set_prio)(struct dpll_pin *pin, struct dpll_device *dpll, int prio); }; enum dpll_pin_type {