mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	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: 9d71b54b65 ("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>
			
			
This commit is contained in:
		
							parent
							
								
									830ead5fb0
								
							
						
					
					
						commit
						db2ec3c946
					
				
					 1 changed files with 27 additions and 2 deletions
				
			
		| 
						 | 
					@ -553,6 +553,24 @@ __dpll_device_change_ntf(struct dpll_device *dpll)
 | 
				
			||||||
	return dpll_device_event_send(DPLL_CMD_DEVICE_CHANGE_NTF, dpll);
 | 
						return dpll_device_event_send(DPLL_CMD_DEVICE_CHANGE_NTF, dpll);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static bool dpll_pin_available(struct dpll_pin *pin)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct dpll_pin_ref *par_ref;
 | 
				
			||||||
 | 
						unsigned long i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!xa_get_mark(&dpll_pin_xa, pin->id, DPLL_REGISTERED))
 | 
				
			||||||
 | 
							return false;
 | 
				
			||||||
 | 
						xa_for_each(&pin->parent_refs, i, par_ref)
 | 
				
			||||||
 | 
							if (xa_get_mark(&dpll_pin_xa, par_ref->pin->id,
 | 
				
			||||||
 | 
									DPLL_REGISTERED))
 | 
				
			||||||
 | 
								return true;
 | 
				
			||||||
 | 
						xa_for_each(&pin->dpll_refs, i, par_ref)
 | 
				
			||||||
 | 
							if (xa_get_mark(&dpll_device_xa, par_ref->dpll->id,
 | 
				
			||||||
 | 
									DPLL_REGISTERED))
 | 
				
			||||||
 | 
								return true;
 | 
				
			||||||
 | 
						return false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * dpll_device_change_ntf - notify that the dpll device has been changed
 | 
					 * dpll_device_change_ntf - notify that the dpll device has been changed
 | 
				
			||||||
 * @dpll: registered dpll pointer
 | 
					 * @dpll: registered dpll pointer
 | 
				
			||||||
| 
						 | 
					@ -579,7 +597,7 @@ dpll_pin_event_send(enum dpll_cmd event, struct dpll_pin *pin)
 | 
				
			||||||
	int ret = -ENOMEM;
 | 
						int ret = -ENOMEM;
 | 
				
			||||||
	void *hdr;
 | 
						void *hdr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (WARN_ON(!xa_get_mark(&dpll_pin_xa, pin->id, DPLL_REGISTERED)))
 | 
						if (!dpll_pin_available(pin))
 | 
				
			||||||
		return -ENODEV;
 | 
							return -ENODEV;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	msg = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
 | 
						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)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	pin = dpll_pin_find_from_nlattr(info);
 | 
						pin = dpll_pin_find_from_nlattr(info);
 | 
				
			||||||
	if (!IS_ERR(pin)) {
 | 
						if (!IS_ERR(pin)) {
 | 
				
			||||||
 | 
							if (!dpll_pin_available(pin)) {
 | 
				
			||||||
 | 
								nlmsg_free(msg);
 | 
				
			||||||
 | 
								return -ENODEV;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		ret = dpll_msg_add_pin_handle(msg, pin);
 | 
							ret = dpll_msg_add_pin_handle(msg, pin);
 | 
				
			||||||
		if (ret) {
 | 
							if (ret) {
 | 
				
			||||||
			nlmsg_free(msg);
 | 
								nlmsg_free(msg);
 | 
				
			||||||
| 
						 | 
					@ -1179,6 +1201,8 @@ int dpll_nl_pin_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	xa_for_each_marked_start(&dpll_pin_xa, i, pin, DPLL_REGISTERED,
 | 
						xa_for_each_marked_start(&dpll_pin_xa, i, pin, DPLL_REGISTERED,
 | 
				
			||||||
				 ctx->idx) {
 | 
									 ctx->idx) {
 | 
				
			||||||
 | 
							if (!dpll_pin_available(pin))
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
		hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid,
 | 
							hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid,
 | 
				
			||||||
				  cb->nlh->nlmsg_seq,
 | 
									  cb->nlh->nlmsg_seq,
 | 
				
			||||||
				  &dpll_nl_family, NLM_F_MULTI,
 | 
									  &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,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	info->user_ptr[0] = xa_load(&dpll_pin_xa,
 | 
						info->user_ptr[0] = xa_load(&dpll_pin_xa,
 | 
				
			||||||
				    nla_get_u32(info->attrs[DPLL_A_PIN_ID]));
 | 
									    nla_get_u32(info->attrs[DPLL_A_PIN_ID]));
 | 
				
			||||||
	if (!info->user_ptr[0]) {
 | 
						if (!info->user_ptr[0] ||
 | 
				
			||||||
 | 
						    !dpll_pin_available(info->user_ptr[0])) {
 | 
				
			||||||
		NL_SET_ERR_MSG(info->extack, "pin not found");
 | 
							NL_SET_ERR_MSG(info->extack, "pin not found");
 | 
				
			||||||
		ret = -ENODEV;
 | 
							ret = -ENODEV;
 | 
				
			||||||
		goto unlock_dev;
 | 
							goto unlock_dev;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue