drm/tests: hdmi: Fix memory leaks in drm_display_mode_from_cea_vic()
[drm/drm-misc.git] / net / ethtool / phc_vclocks.c
blobcadaabed60bd96be2c4c81560d916df5f607b0c9
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright 2021 NXP
4 */
5 #include "netlink.h"
6 #include "common.h"
8 struct phc_vclocks_req_info {
9 struct ethnl_req_info base;
12 struct phc_vclocks_reply_data {
13 struct ethnl_reply_data base;
14 int num;
15 int *index;
18 #define PHC_VCLOCKS_REPDATA(__reply_base) \
19 container_of(__reply_base, struct phc_vclocks_reply_data, base)
21 const struct nla_policy ethnl_phc_vclocks_get_policy[] = {
22 [ETHTOOL_A_PHC_VCLOCKS_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy),
25 static int phc_vclocks_prepare_data(const struct ethnl_req_info *req_base,
26 struct ethnl_reply_data *reply_base,
27 const struct genl_info *info)
29 struct phc_vclocks_reply_data *data = PHC_VCLOCKS_REPDATA(reply_base);
30 struct net_device *dev = reply_base->dev;
31 int ret;
33 ret = ethnl_ops_begin(dev);
34 if (ret < 0)
35 return ret;
36 data->num = ethtool_get_phc_vclocks(dev, &data->index);
37 ethnl_ops_complete(dev);
39 return ret;
42 static int phc_vclocks_reply_size(const struct ethnl_req_info *req_base,
43 const struct ethnl_reply_data *reply_base)
45 const struct phc_vclocks_reply_data *data =
46 PHC_VCLOCKS_REPDATA(reply_base);
47 int len = 0;
49 if (data->num > 0) {
50 len += nla_total_size(sizeof(u32));
51 len += nla_total_size(sizeof(s32) * data->num);
54 return len;
57 static int phc_vclocks_fill_reply(struct sk_buff *skb,
58 const struct ethnl_req_info *req_base,
59 const struct ethnl_reply_data *reply_base)
61 const struct phc_vclocks_reply_data *data =
62 PHC_VCLOCKS_REPDATA(reply_base);
64 if (data->num <= 0)
65 return 0;
67 if (nla_put_u32(skb, ETHTOOL_A_PHC_VCLOCKS_NUM, data->num) ||
68 nla_put(skb, ETHTOOL_A_PHC_VCLOCKS_INDEX,
69 sizeof(s32) * data->num, data->index))
70 return -EMSGSIZE;
72 return 0;
75 static void phc_vclocks_cleanup_data(struct ethnl_reply_data *reply_base)
77 const struct phc_vclocks_reply_data *data =
78 PHC_VCLOCKS_REPDATA(reply_base);
80 kfree(data->index);
83 const struct ethnl_request_ops ethnl_phc_vclocks_request_ops = {
84 .request_cmd = ETHTOOL_MSG_PHC_VCLOCKS_GET,
85 .reply_cmd = ETHTOOL_MSG_PHC_VCLOCKS_GET_REPLY,
86 .hdr_attr = ETHTOOL_A_PHC_VCLOCKS_HEADER,
87 .req_info_size = sizeof(struct phc_vclocks_req_info),
88 .reply_data_size = sizeof(struct phc_vclocks_reply_data),
90 .prepare_data = phc_vclocks_prepare_data,
91 .reply_size = phc_vclocks_reply_size,
92 .fill_reply = phc_vclocks_fill_reply,
93 .cleanup_data = phc_vclocks_cleanup_data,