Skip to contentSkip to conversation

Staging: gdm724x: code style improvements

PATCH In review Tolga Ceylan 2 participants 3 messages Feb 13, 2015 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: gdm724x: code style improvements

Corrections based on checkpatch.pl with --strict.
1) Lines over 80 were corrected
2) Alignment should match open paranthesis cases corrected
3) Comparisons such as if (x == NULL) rewritten as if (!x)
4) CamelCase variables renamed
5) Missing spaces between operators added
6) Unnecessary blank lines removed
7) in mem alloc arguments sizeof(struct foo) rewritten as sizeof(*foo_obj)

---
 drivers/staging/gdm724x/gdm_endian.c |  9 +++----
 drivers/staging/gdm724x/gdm_endian.h |  4 +--
 drivers/staging/gdm724x/gdm_lte.c    | 42 ++++++++++++++---------------
 drivers/staging/gdm724x/gdm_lte.h    | 14 +++++-----
 drivers/staging/gdm724x/gdm_mux.c    | 27 +++++++++----------
 drivers/staging/gdm724x/gdm_mux.h    |  4 +--
 drivers/staging/gdm724x/gdm_tty.c    |  7 +++--
 drivers/staging/gdm724x/gdm_tty.h    |  6 ++---
 drivers/staging/gdm724x/gdm_usb.c    | 52 ++++++++++++++++++------------------
 drivers/staging/gdm724x/gdm_usb.h    |  6 ++---
 drivers/staging/gdm724x/hci_packet.h |  5 ++--
 drivers/staging/gdm724x/netlink_k.c  | 13 ++++-----
 drivers/staging/gdm724x/netlink_k.h  |  3 ++-
 13 files changed, 93 insertions(+), 99 deletions(-)
drivers/staging/gdm724x/gdm_endian.c +4 -5
index f6cc90a..032aafa 100644
@@ -31,7 +31,6 @@ void gdm_set_endian(struct gdm_endian *ed, u8 dev_endian)
 		ed->host_ed = ENDIANNESS_LITTLE;
 	else
 		ed->host_ed = ENDIANNESS_BIG;
-
 }
 
 u16 gdm_cpu_to_dev16(struct gdm_endian *ed, u16 x)
@@ -39,7 +38,7 @@ u16 gdm_cpu_to_dev16(struct gdm_endian *ed, u16 x)
 	if (ed->dev_ed == ed->host_ed)
 		return x;
 
-	return Endian16_Swap(x);
+	return ENDIAN16_SWAP(x);
 }
 
 u16 gdm_dev16_to_cpu(struct gdm_endian *ed, u16 x)
@@ -47,7 +46,7 @@ u16 gdm_dev16_to_cpu(struct gdm_endian *ed, u16 x)
 	if (ed->dev_ed == ed->host_ed)
 		return x;
 
-	return Endian16_Swap(x);
+	return ENDIAN16_SWAP(x);
 }
 
 u32 gdm_cpu_to_dev32(struct gdm_endian *ed, u32 x)
@@ -55,7 +54,7 @@ u32 gdm_cpu_to_dev32(struct gdm_endian *ed, u32 x)
 	if (ed->dev_ed == ed->host_ed)
 		return x;
 
-	return Endian32_Swap(x);
+	return ENDIAN32_SWAP(x);
 }
 
 u32 gdm_dev32_to_cpu(struct gdm_endian *ed, u32 x)
@@ -63,5 +62,5 @@ u32 gdm_dev32_to_cpu(struct gdm_endian *ed, u32 x)
 	if (ed->dev_ed == ed->host_ed)
 		return x;
 
-	return Endian32_Swap(x);
+	return ENDIAN32_SWAP(x);
 }
drivers/staging/gdm724x/gdm_endian.h +2 -2
index 9b2531f..12e3fb0 100644
@@ -16,11 +16,11 @@
 
 #include <linux/types.h>
 
-#define Endian16_Swap(value) \
+#define ENDIAN16_SWAP(value) \
 	((((u16)((value) & 0x00FF)) << 8) | \
 	 (((u16)((value) & 0xFF00)) >> 8))
 
-#define Endian32_Swap(value) \
+#define ENDIAN32_SWAP(value) \
 	((((u32)((value) & 0x000000FF)) << 24) | \
 	 (((u32)((value) & 0x0000FF00)) << 8) | \
 	 (((u32)((value) & 0x00FF0000)) >> 8) | \
drivers/staging/gdm724x/gdm_lte.c +21 -21

131 lines not on this page · raw message

drivers/staging/gdm724x/gdm_lte.h +7 -7
index 88414e5..3ecaff1 100644
@@ -47,15 +47,15 @@ struct phy_dev {
 	void	*priv_dev;
 	struct net_device *dev[MAX_NIC_TYPE];
 	int	(*send_hci_func)(void *priv_dev, void *data, int len,
-			void (*cb)(void *cb_data), void *cb_data);
+				 void (*cb)(void *cb_data), void *cb_data);
 	int	(*send_sdu_func)(void *priv_dev, void *data, int len,
-			unsigned int dftEpsId, unsigned int epsId,
-			void (*cb)(void *cb_data), void *cb_data,
-			int dev_idx, int nic_type);
+				 unsigned int dft_eps_id, unsigned int eps_id,
+				 void (*cb)(void *cb_data), void *cb_data,
+				 int dev_idx, int nic_type);
 	int	(*rcv_func)(void *priv_dev,
-			int (*cb)(void *cb_data, void *data, int len,
-				  int context),
-			void *cb_data, int context);
+			    int (*cb)(void *cb_data, void *data, int len,
+				      int context),
+			    void *cb_data, int context);
 	struct gdm_endian * (*get_endian)(void *priv_dev);
 };
 
drivers/staging/gdm724x/gdm_mux.c +12 -15
index d1ab996..177594f 100644
@@ -48,7 +48,6 @@ static const struct usb_device_id id_table[] = {
 	{}
 };
 
-
 MODULE_DEVICE_TABLE(usb, id_table);
 
 static int packet_type_to_index(u16 packetType)
@@ -67,7 +66,7 @@ static struct mux_tx *alloc_mux_tx(int len)
 {
 	struct mux_tx *t = NULL;
 
-	t = kzalloc(sizeof(struct mux_tx), GFP_ATOMIC);
+	t = kzalloc(sizeof(*t), GFP_ATOMIC);
 	if (!t)
 		return NULL;
 
@@ -96,7 +95,7 @@ static struct mux_rx *alloc_mux_rx(void)
 {
 	struct mux_rx *r = NULL;
 
-	r = kzalloc(sizeof(struct mux_rx), GFP_KERNEL);
+	r = kzalloc(sizeof(*r), GFP_KERNEL);
 	if (!r)
 		return NULL;
 
@@ -150,7 +149,6 @@ static void put_rx_struct(struct rx_cxt *rx, struct mux_rx *r)
 	spin_unlock_irqrestore(&rx->free_list_lock, flags);
 }
 
-
 static int up_to_host(struct mux_rx *r)
 {
 	struct mux_dev *mux_dev = (struct mux_dev *)r->mux_dev;
@@ -282,8 +280,10 @@ static void gdm_mux_rcv_complete(struct urb *urb)
 	}
 }
 
-static int gdm_mux_recv(void *priv_dev, int (*cb)(void *data, int len,
-			int tty_index, struct tty_dev *tty_dev, int complete))
+static int gdm_mux_recv(void *priv_dev,
+			int (*cb)(void *data, int len,
+				  int tty_index, struct tty_dev *tty_dev,
+				  int complete))
 {
 	struct mux_dev *mux_dev = priv_dev;
 	struct usb_device *usbdev = mux_dev->usbdev;
@@ -391,8 +391,8 @@ static int gdm_mux_send(void *priv_dev, void *data, int len, int tty_index,
 	mux_header->payload_size = __cpu_to_le32((u32)len);
 	mux_header->packet_type = __cpu_to_le16(packet_type[tty_index]);
 
-	memcpy(t->buf+MUX_HEADER_SIZE, data, len);
-	memset(t->buf+MUX_HEADER_SIZE+len, 0, dummy_cnt);
+	memcpy(t->buf + MUX_HEADER_SIZE, data, len);
+	memset(t->buf + MUX_HEADER_SIZE + len, 0, dummy_cnt);
 
 	t->len = total_len;
 	t->callback = cb;
@@ -476,7 +476,6 @@ static void release_usb(struct mux_dev *mux_dev)
 	spin_unlock_irqrestore(&rx->to_host_lock, flags);
 }
 
-
 static int init_usb(struct mux_dev *mux_dev)
 {
 	struct mux_rx *r;
@@ -494,7 +493,7 @@ static int init_usb(struct mux_dev *mux_dev)
 
 	for (i = 0; i < MAX_ISSUE_NUM * 2; i++) {
 		r = alloc_mux_rx();
-		if (r == NULL) {
+		if (!r) {
 			ret = -ENOMEM;
 			break;
 		}
@@ -528,11 +527,11 @@ static int gdm_mux_probe(struct usb_interface *intf,
 	if (bInterfaceNumber != 2)
 		return -ENODEV;
 
-	mux_dev = kzalloc(sizeof(struct mux_dev), GFP_KERNEL);
+	mux_dev = kzalloc(sizeof(*mux_dev), GFP_KERNEL);
 	if (!mux_dev)
 		return -ENOMEM;
 
-	tty_dev = kzalloc(sizeof(struct tty_dev), GFP_KERNEL);
+	tty_dev = kzalloc(sizeof(*tty_dev), GFP_KERNEL);
 	if (!tty_dev) {
 		ret = -ENOMEM;
 		goto err_free_mux;
@@ -614,7 +613,6 @@ static int gdm_mux_suspend(struct usb_interface *intf, pm_message_t pm_msg)
 
 	mux_dev->usb_state = PM_SUSPEND;
 
-
 	spin_lock_irqsave(&rx->submit_list_lock, flags);
 	list_for_each_entry_safe(r, r_next, &rx->rx_submit_list,
 				 rx_submit_list) {
@@ -662,9 +660,8 @@ static struct usb_driver gdm_mux_driver = {
 
 static int __init gdm_usb_mux_init(void)
 {
-
 	mux_rx_wq = create_workqueue("mux_rx_wq");
-	if (mux_rx_wq == NULL) {
+	if (!mux_rx_wq) {
 		pr_err("work queue create fail\n");
 		return -1;
 	}
drivers/staging/gdm724x/gdm_mux.h +2 -2
index 3d50383..0871b8f 100644
@@ -27,8 +27,8 @@
 
 #define START_FLAG 0xA512485A
 #define MUX_HEADER_SIZE 14
-#define MUX_TX_MAX_SIZE (1024*10)
-#define MUX_RX_MAX_SIZE (1024*30)
+#define MUX_TX_MAX_SIZE (1024 * 10)
+#define MUX_RX_MAX_SIZE (1024 * 30)
 #define AT_PKT_TYPE 0xF011
 #define DM_PKT_TYPE 0xF010
 
drivers/staging/gdm724x/gdm_tty.c +3 -4
index 001348c..60b52a3 100644
@@ -88,7 +88,7 @@ static int gdm_tty_install(struct tty_driver *driver, struct tty_struct *tty)
 
 	mutex_lock(&gdm_table_lock);
 	gdm = gdm_table[i][j];
-	if (gdm == NULL) {
+	if (!gdm) {
 		mutex_unlock(&gdm_table_lock);
 		return -ENODEV;
 	}
@@ -193,7 +193,7 @@ static int gdm_tty_write(struct tty_struct *tty, const unsigned char *buf,
 		sending_len = remain > MUX_TX_MAX_SIZE ? MUX_TX_MAX_SIZE :
 							 remain;
 		gdm_tty_send(gdm,
-			     (void *)(buf+sent_len),
+			     (void *)(buf + sent_len),
 			     sending_len,
 			     gdm->index,
 			     gdm_tty_send_complete,
@@ -225,8 +225,7 @@ int register_lte_tty_device(struct tty_dev *tty_dev, struct device *device)
 	int j;
 
 	for (i = 0; i < TTY_MAX_COUNT; i++) {
-
-		gdm = kmalloc(sizeof(struct gdm), GFP_KERNEL);
+		gdm = kmalloc(sizeof(*gdm), GFP_KERNEL);
 		if (!gdm)
 			return -ENOMEM;
 
drivers/staging/gdm724x/gdm_tty.h +2 -4
index 297438b..720c812 100644
@@ -17,10 +17,8 @@
 #include <linux/types.h>
 #include <linux/tty.h>
 
-
-#define TTY_MAX_COUNT		2
-
-#define MAX_ISSUE_NUM 3
+#define TTY_MAX_COUNT	2
+#define MAX_ISSUE_NUM	3
 
 enum TO_HOST_RESULT {
 	TO_HOST_BUFFER_REQUEST_FAIL = 1,
drivers/staging/gdm724x/gdm_usb.c +26 -26

182 lines not on this page · raw message

drivers/staging/gdm724x/gdm_usb.h +3 -3
index e6486e7..ffb3d99 100644
@@ -26,10 +26,10 @@
 #define PM_SUSPEND 1
 #define AUTO_SUSPEND_TIMER 5000 /* ms */
 
-#define RX_BUF_SIZE		(1024*32)
-#define TX_BUF_SIZE		(1024*32)
+#define RX_BUF_SIZE		(1024 * 32)
+#define TX_BUF_SIZE		(1024 * 32)
 #define SDU_BUF_SIZE	2048
-#define MAX_SDU_SIZE	(1024*30)
+#define MAX_SDU_SIZE	(1024 * 30)
 #define MAX_PACKET_IN_MULTI_SDU	256
 
 #define VID_GCT			0x1076
drivers/staging/gdm724x/hci_packet.h +2 -3
index 7fba8a6..ca788ba 100644
@@ -50,7 +50,7 @@ struct tlv {
 struct sdu_header {
 	u16 cmd_evt;
 	u16 len;
-	u32 dftEpsId;
+	u32 dft_eps_id;
 	u32 bearer_ID;
 	u32 nic_type;
 } __packed;
@@ -58,7 +58,7 @@ struct sdu_header {
 struct sdu {
 	u16 cmd_evt;
 	u16 len;
-	u32 dftEpsId;
+	u32 dft_eps_id;
 	u32 bearer_ID;
 	u32 nic_type;
 	u8 data[0];
@@ -89,5 +89,4 @@ struct hci_connect_ind {
 	u32 connect;
 } __packed;
 
-
 #endif /* _HCI_PACKET_H_ */
drivers/staging/gdm724x/netlink_k.c +7 -6
index 59a1830..4aff6e0 100644
@@ -34,8 +34,8 @@ static struct semaphore netlink_mutex;
 #define ND_NLMSG_SPACE(len)	(NLMSG_SPACE(len) + ND_IFINDEX_LEN)
 #define ND_NLMSG_DATA(nlh)	((void *)((char *)NLMSG_DATA(nlh) + \
 						  ND_IFINDEX_LEN))
-#define ND_NLMSG_S_LEN(len)	(len+ND_IFINDEX_LEN)
-#define ND_NLMSG_R_LEN(nlh)	(nlh->nlmsg_len-ND_IFINDEX_LEN)
+#define ND_NLMSG_S_LEN(len)	(len + ND_IFINDEX_LEN)
+#define ND_NLMSG_R_LEN(nlh)	(nlh->nlmsg_len - ND_IFINDEX_LEN)
 #define ND_NLMSG_IFIDX(nlh)	NLMSG_DATA(nlh)
 #define ND_MAX_MSG_LEN		(1024 * 32)
 
@@ -88,7 +88,8 @@ static void netlink_rcv(struct sk_buff *skb)
 }
 
 struct sock *netlink_init(int unit,
-	void (*cb)(struct net_device *dev, u16 type, void *msg, int len))
+			  void (*cb)(struct net_device *dev, u16 type,
+				     void *msg, int len))
 {
 	struct sock *sock;
 	struct netlink_kernel_cfg cfg = {
@@ -122,7 +123,7 @@ int netlink_send(struct sock *sock, int group, u16 type, void *msg, int len)
 	if (group > ND_MAX_GROUP)
 		return -EINVAL;
 
-	if (!netlink_has_listeners(sock, group+1))
+	if (!netlink_has_listeners(sock, group + 1))
 		return -ESRCH;
 
 	skb = alloc_skb(NLMSG_SPACE(len), GFP_ATOMIC);
@@ -136,14 +137,14 @@ int netlink_send(struct sock *sock, int group, u16 type, void *msg, int len)
 	NETLINK_CB(skb).portid = 0;
 	NETLINK_CB(skb).dst_group = 0;
 
-	ret = netlink_broadcast(sock, skb, 0, group+1, GFP_ATOMIC);
+	ret = netlink_broadcast(sock, skb, 0, group + 1, GFP_ATOMIC);
 	if (!ret)
 		return len;
 
 	if (ret != -ESRCH)
 		pr_err("nl broadcast g=%d, t=%d, l=%d, r=%d\n",
 		       group, type, len, ret);
-	else if (netlink_has_listeners(sock, group+1))
+	else if (netlink_has_listeners(sock, group + 1))
 		return -EAGAIN;
 
 	return ret;
drivers/staging/gdm724x/netlink_k.h +2 -1
index 589486d..e9e78d8 100644
@@ -18,7 +18,8 @@
 #include <net/sock.h>
 
 struct sock *netlink_init(int unit,
-	void (*cb)(struct net_device *dev, u16 type, void *msg, int len));
+			  void (*cb)(struct net_device *dev, u16 type,
+				     void *msg, int len));
 void netlink_exit(struct sock *sock);
 int netlink_send(struct sock *sock, int group, u16 type, void *msg, int len);
 
Signature · 1 line
2.3.0
#1 lore raw
Quoted 9 lines · Tolga Ceylan

Corrections based on checkpatch.pl with --strict.
1) Lines over 80 were corrected
2) Alignment should match open paranthesis cases corrected
3) Comparisons such as if (x == NULL) rewritten as if (!x)
4) CamelCase variables renamed
5) Missing spaces between operators added
6) Unnecessary blank lines removed
7) in mem alloc arguments sizeof(struct foo) rewritten as sizeof(*foo_obj)

You're doing too many things at one. This should probably be split into 7 patches.

drivers/staging/gdm724x/gdm_endian.c u16 gdm_cpu_to_dev16(struct gdm_endian *ed, u16 x) · line 42

Quoted 8 lines

u16 gdm_cpu_to_dev16(struct gdm_endian *ed, u16 x)

drivers/staging/gdm724x/gdm_endian.c +1 -1
@@ -39,7 +38,7 @@ u16 gdm_cpu_to_dev16(struct gdm_endian *ed, u16 x)
 	if (ed->dev_ed == ed->host_ed)
 		return x;
 
-	return Endian16_Swap(x);
+	return ENDIAN16_SWAP(x);
 }

All the changes are good except these. We have standard macros cpu_to_be16()/le16() and back for these.

regards,
dan carpenter

#2 lore raw
Quoted 3 lines · Dan Carpenter

You're doing too many things at one. This should probably be split into 7 patches.

I will split this up and resubmit.

Quoted 14 lines

drivers/staging/gdm724x/gdm_endian.c u16 gdm_cpu_to_dev16(struct gdm_endian *ed, u16 x) · line 42

Quoted 10 lines

u16 gdm_cpu_to_dev16(struct gdm_endian *ed, u16 x)

drivers/staging/gdm724x/gdm_endian.c +1 -1
@@ -39,7 +38,7 @@ u16 gdm_cpu_to_dev16(struct gdm_endian *ed, u16 x)
      if (ed->dev_ed == ed->host_ed)
              return x;
 
-     return Endian16_Swap(x);
+     return ENDIAN16_SWAP(x);
 }

All the changes are good except these. We have standard macros cpu_to_be16()/le16() and back for these.

Quoted 2 lines

regards,
dan carpenter

Thanks, I'll skip this one.

Regards,
Tolga Ceylan