gpio: rcar: Fix runtime PM imbalance on error
[linux/fpc-iii.git] / drivers / net / ethernet / rocker / rocker_tlv.c
blob256447b7599ba41f7a31ebe15eeac242be722ab1
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * drivers/net/ethernet/rocker/rocker_tlv.c - Rocker switch device driver
4 * Copyright (c) 2014-2016 Jiri Pirko <jiri@mellanox.com>
5 * Copyright (c) 2014 Scott Feldman <sfeldma@gmail.com>
6 */
8 #include <linux/types.h>
9 #include <linux/string.h>
10 #include <linux/errno.h>
12 #include "rocker_hw.h"
13 #include "rocker_tlv.h"
15 void rocker_tlv_parse(const struct rocker_tlv **tb, int maxtype,
16 const char *buf, int buf_len)
18 const struct rocker_tlv *tlv;
19 const struct rocker_tlv *head = (const struct rocker_tlv *) buf;
20 int rem;
22 memset(tb, 0, sizeof(struct rocker_tlv *) * (maxtype + 1));
24 rocker_tlv_for_each(tlv, head, buf_len, rem) {
25 u32 type = rocker_tlv_type(tlv);
27 if (type > 0 && type <= maxtype)
28 tb[type] = tlv;
32 int rocker_tlv_put(struct rocker_desc_info *desc_info,
33 int attrtype, int attrlen, const void *data)
35 int tail_room = desc_info->data_size - desc_info->tlv_size;
36 int total_size = rocker_tlv_total_size(attrlen);
37 struct rocker_tlv *tlv;
39 if (unlikely(tail_room < total_size))
40 return -EMSGSIZE;
42 tlv = rocker_tlv_start(desc_info);
43 desc_info->tlv_size += total_size;
44 tlv->type = attrtype;
45 tlv->len = rocker_tlv_attr_size(attrlen);
46 memcpy(rocker_tlv_data(tlv), data, attrlen);
47 memset((char *) tlv + tlv->len, 0, rocker_tlv_padlen(attrlen));
48 return 0;