Skip to content

Commit db2ec3c

Browse files
kubalewskidavem330
authored andcommitted
dpll: fix userspace availability of pins
If parent pin was unregistered but child pin was not, the userspace would see the "zombie" pins - the ones that were registered with a parent pin (dpll_pin_on_pin_register(..)). Technically those are not available - as there is no dpll device in the system. Do not dump those pins and prevent userspace from any interaction with them. Provide a unified function to determine if the pin is available and use it before acting/responding for user requests. Fixes: 9d71b54 ("dpll: netlink: Add DPLL framework base functions") Reviewed-by: Jan Glaza <jan.glaza@intel.com> Reviewed-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 830ead5 commit db2ec3c

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

drivers/dpll/dpll_netlink.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,24 @@ __dpll_device_change_ntf(struct dpll_device *dpll)
553553
return dpll_device_event_send(DPLL_CMD_DEVICE_CHANGE_NTF, dpll);
554554
}
555555

556+
static bool dpll_pin_available(struct dpll_pin *pin)
557+
{
558+
struct dpll_pin_ref *par_ref;
559+
unsigned long i;
560+
561+
if (!xa_get_mark(&dpll_pin_xa, pin->id, DPLL_REGISTERED))
562+
return false;
563+
xa_for_each(&pin->parent_refs, i, par_ref)
564+
if (xa_get_mark(&dpll_pin_xa, par_ref->pin->id,
565+
DPLL_REGISTERED))
566+
return true;
567+
xa_for_each(&pin->dpll_refs, i, par_ref)
568+
if (xa_get_mark(&dpll_device_xa, par_ref->dpll->id,
569+
DPLL_REGISTERED))
570+
return true;
571+
return false;
572+
}
573+
556574
/**
557575
* dpll_device_change_ntf - notify that the dpll device has been changed
558576
* @dpll: registered dpll pointer
@@ -579,7 +597,7 @@ dpll_pin_event_send(enum dpll_cmd event, struct dpll_pin *pin)
579597
int ret = -ENOMEM;
580598
void *hdr;
581599

582-
if (WARN_ON(!xa_get_mark(&dpll_pin_xa, pin->id, DPLL_REGISTERED)))
600+
if (!dpll_pin_available(pin))
583601
return -ENODEV;
584602

585603
msg = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
@@ -1130,6 +1148,10 @@ int dpll_nl_pin_id_get_doit(struct sk_buff *skb, struct genl_info *info)
11301148
}
11311149
pin = dpll_pin_find_from_nlattr(info);
11321150
if (!IS_ERR(pin)) {
1151+
if (!dpll_pin_available(pin)) {
1152+
nlmsg_free(msg);
1153+
return -ENODEV;
1154+
}
11331155
ret = dpll_msg_add_pin_handle(msg, pin);
11341156
if (ret) {
11351157
nlmsg_free(msg);
@@ -1179,6 +1201,8 @@ int dpll_nl_pin_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
11791201

11801202
xa_for_each_marked_start(&dpll_pin_xa, i, pin, DPLL_REGISTERED,
11811203
ctx->idx) {
1204+
if (!dpll_pin_available(pin))
1205+
continue;
11821206
hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid,
11831207
cb->nlh->nlmsg_seq,
11841208
&dpll_nl_family, NLM_F_MULTI,
@@ -1441,7 +1465,8 @@ int dpll_pin_pre_doit(const struct genl_split_ops *ops, struct sk_buff *skb,
14411465
}
14421466
info->user_ptr[0] = xa_load(&dpll_pin_xa,
14431467
nla_get_u32(info->attrs[DPLL_A_PIN_ID]));
1444-
if (!info->user_ptr[0]) {
1468+
if (!info->user_ptr[0] ||
1469+
!dpll_pin_available(info->user_ptr[0])) {
14451470
NL_SET_ERR_MSG(info->extack, "pin not found");
14461471
ret = -ENODEV;
14471472
goto unlock_dev;

0 commit comments

Comments
 (0)