drm/dp: Fine-tuning for three function implementations
Subsystems (3)
cover drm/dp: Fine-tuning for three function implementations
From: Markus Elfring <[email protected]>
Date: Mon, 1 May 2017 18:38:08 +0200
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (4):
Use seq_putc() in drm_dp_mst_dump_topology()
Combine two seq_printf() calls into one call in drm_dp_mst_dump_topology() Replace six seq_printf() calls by seq_puts() in drm_dp_mst_dump_topology() Adjust four checks for null pointers
drivers/gpu/drm/drm_dp_mst_topology.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-)
Signature · 1 line
2.12.2
PATCH 1/4 drm/dp: Use seq_putc() in drm_dp_mst_dump_topology()
From: Markus Elfring <[email protected]>
Date: Mon, 1 May 2017 17:08:56 +0200
A few single characters (line breaks) should be put into a sequence. Thus use the corresponding function "seq_putc".
This issue was detected by using the Coccinelle software.
--- drivers/gpu/drm/drm_dp_mst_topology.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_dp_mst_topology.c +4 -4
@@ -2840,17 +2840,17 @@ void drm_dp_mst_dump_topology(struct seq_file *m,seq_printf (m,"dpcd: " );for (i =0 ; i <DP_RECEIVER_CAP_SIZE ; i++)seq_printf (m,"%02x " , buf[i]); -seq_printf (m,"\n" ); +seq_putc (m,'\n' ); ret =drm_dp_dpcd_read (mgr->aux,DP_FAUX_CAP , buf,2 );seq_printf (m,"faux/mst: " );for (i =0 ; i <2 ; i++)seq_printf (m,"%02x " , buf[i]); -seq_printf (m,"\n" ); +seq_putc (m,'\n' ); ret =drm_dp_dpcd_read (mgr->aux,DP_MSTM_CTRL , buf,1 );seq_printf (m,"mst ctrl: " );for (i =0 ; i <1 ; i++)seq_printf (m,"%02x " , buf[i]); -seq_printf (m,"\n" ); +seq_putc (m,'\n' );/* dump the standard OUI branch header */ ret =drm_dp_dpcd_read (mgr->aux,DP_BRANCH_OUI , buf,DP_BRANCH_OUI_HEADER_SIZE );
@@ -2868,7 +2868,7 @@ void drm_dp_mst_dump_topology(struct seq_file *m,seq_printf (m,"payload table: " );for (i =0 ; i <63 ; i++)seq_printf (m,"%02x " , buf[i]); -seq_printf (m,"\n" ); +seq_putc (m,'\n' ); } }
Signature · 1 line
2.12.2
Re: [PATCH 1/4] drm/dp: Use seq_putc() in drm_dp_mst_dump_topology()
Quoted 7 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 1 May 2017 17:08:56 +0200A few single characters (line breaks) should be put into a sequence. Thus use the corresponding function "
seq_putc".This issue was detected by using the Coccinelle software.
[]
drivers/gpu/drm/drm_dp_mst_topology.c
Quoted 1 line
drivers/gpu/drm/drm_dp_mst_topology.c +0
-0
[]
Quoted 8 lines
drivers/gpu/drm/drm_dp_mst_topology.c +1
-1@@ -2840,17 +2840,17 @@ void drm_dp_mst_dump_topology(struct seq_file *m,seq_printf (m,"dpcd: " );for (i =0 ; i <DP_RECEIVER_CAP_SIZE ; i++)seq_printf (m,"%02x " , buf[i]); -seq_printf (m,"\n" ); +seq_putc (m,'\n' ); ret =drm_dp_dpcd_read (mgr->aux,DP_FAUX_CAP , buf,2 );seq_printf (m,"faux/mst: " );
drivers/gpu/drm/drm_dp_mst_topology.c void drm_dp_mst_dump_topology(struct seq_file *m, · line 2853
Quoted 10 lines
drivers/gpu/drm/drm_dp_mst_topology.c +2
-2for (i =0 ; i <2 ; i++)seq_printf (m,"%02x " , buf[i]); -seq_printf (m,"\n" ); +seq_putc (m,'\n' ); ret =drm_dp_dpcd_read (mgr->aux,DP_MSTM_CTRL , buf,1 );seq_printf (m,"mst ctrl: " );for (i =0 ; i <1 ; i++)seq_printf (m,"%02x " , buf[i]); -seq_printf (m,"\n" ); +seq_putc (m,'\n' );
Please don't be _just_ mechanical.
Stop and read the code the tools you use using suggest modifying and see how you can improve it for a human reader.
If you're really trying to improve these to make them more readable or smaller object code size, you should use the vsprintf extensions like:
seq_printf(m, "dpcd: %*ph\n", DP_RECEIVER_CAP_SIZE, buf);
And if these are supposed to be correct, then the return value from drm_dp_dpcd_read should be tested too.
Likely these repeated code blocks could be put into a helper function.
PATCH 2/4 drm/dp: Combine two seq_printf() calls into one call in drm_dp_mst_dump_topology()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 1 May 2017 17:15:43 +0200
Some data were put into a sequence by two separate function calls. Print the same data by a single function call instead.
This issue was detected by using the Coccinelle software.
--- drivers/gpu/drm/drm_dp_mst_topology.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_dp_mst_topology.c +2 -2
@@ -2861,8 +2861,8 @@ void drm_dp_mst_dump_topology(struct seq_file *m,for (i =0x3 ; i <0x8 && buf[i]; i++)seq_printf (m,"%c" , buf[i]); -seq_printf (m," revision: hw: %x.%x sw: %x.%x" , buf[0x9 ] >>4 , buf[0x9 ] &0xf , buf[0xa ], buf[0xb ]); -seq_printf (m,"\n" ); +seq_printf (m," revision: hw: %x.%x sw: %x.%x\n" , + buf[0x9 ] >>4 , buf[0x9 ] &0xf , buf[0xa ], buf[0xb ]); bret =dump_dp_payload_table (mgr, buf);if (bret == true) {seq_printf (m,"payload table: " );
Signature · 1 line
2.12.2
PATCH 3/4 drm/dp: Replace six seq_printf() calls by seq_puts() in drm_dp_mst_dump_topology()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 1 May 2017 17:23:24 +0200
Strings which did not contain data format specifications should be put into a sequence. Thus use the corresponding function "seq_puts".
This issue was detected by using the Coccinelle software.
--- drivers/gpu/drm/drm_dp_mst_topology.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_dp_mst_topology.c +6 -6
@@ -2837,27 +2837,27 @@ void drm_dp_mst_dump_topology(struct seq_file *m,bool bret;int ret; ret =drm_dp_dpcd_read (mgr->aux,DP_DPCD_REV , buf,DP_RECEIVER_CAP_SIZE ); -seq_printf (m,"dpcd: " ); +seq_puts (m,"dpcd: " );for (i =0 ; i <DP_RECEIVER_CAP_SIZE ; i++)seq_printf (m,"%02x " , buf[i]);seq_putc (m,'\n' ); ret =drm_dp_dpcd_read (mgr->aux,DP_FAUX_CAP , buf,2 ); -seq_printf (m,"faux/mst: " ); +seq_puts (m,"faux/mst: " );for (i =0 ; i <2 ; i++)seq_printf (m,"%02x " , buf[i]);seq_putc (m,'\n' ); ret =drm_dp_dpcd_read (mgr->aux,DP_MSTM_CTRL , buf,1 ); -seq_printf (m,"mst ctrl: " ); +seq_puts (m,"mst ctrl: " );for (i =0 ; i <1 ; i++)seq_printf (m,"%02x " , buf[i]);seq_putc (m,'\n' );/* dump the standard OUI branch header */ ret =drm_dp_dpcd_read (mgr->aux,DP_BRANCH_OUI , buf,DP_BRANCH_OUI_HEADER_SIZE ); -seq_printf (m,"branch oui: " ); +seq_puts (m,"branch oui: " );for (i =0 ; i <0x3 ; i++)seq_printf (m,"%02x" , buf[i]); -seq_printf (m," devid: " ); +seq_puts (m," devid: " );for (i =0x3 ; i <0x8 && buf[i]; i++)seq_printf (m,"%c" , buf[i]);
@@ -2865,7 +2865,7 @@ void drm_dp_mst_dump_topology(struct seq_file *m, buf[0x9] >> 4, buf[0x9] & 0xf, buf[0xa], buf[0xb]); bret =dump_dp_payload_table (mgr, buf);if (bret == true) { -seq_printf (m,"payload table: " ); +seq_puts (m,"payload table: " );for (i =0 ; i <63 ; i++)seq_printf (m,"%02x " , buf[i]);seq_putc (m,'\n' );
Signature · 1 line
2.12.2
PATCH 4/4 drm/dp: Adjust four checks for null pointers
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 1 May 2017 18:22:52 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script “checkpatch.pl” pointed information out like the following.
Comparison to NULL could be written …
Thus fix the affected source code places.
--- drivers/gpu/drm/drm_dp_mst_topology.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_dp_mst_topology.c +5 -6
@@ -1405,13 +1405,12 @@ static int set_hdr_from_dst_qlock(struct drm_dp_sideband_msg_hdr *hdr,DRM_DEBUG_KMS ("%s: failed to find slot\n" , __func__);return -EAGAIN ; } -if (mstb->tx_slots[0 ] ==NULL && mstb->tx_slots[1 ] ==NULL ) { +if (!mstb->tx_slots[0 ] && !mstb->tx_slots[1 ]) { txmsg->seqno = mstb->last_seqno; mstb->last_seqno ^=1 ; - }else if (mstb->tx_slots[0 ] ==NULL ) - txmsg->seqno =0 ; -else - txmsg->seqno =1 ; + }else { + txmsg->seqno = mstb->tx_slots[0 ] ?1 :0 ; + } mstb->tx_slots[txmsg->seqno] = txmsg; }
@@ -2044,7 +2043,7 @@ int drm_dp_mst_topology_mgr_set_mst(struct drm_dp_mst_topology_mgr *mgr, bool ms/* add initial branch device at LCT 1 */ mstb =drm_dp_add_mst_branch_device (1 ,NULL ); -if (mstb ==NULL ) { +if (!mstb) { ret = -ENOMEM ; goto out_unlock; }
Signature · 1 line
2.12.2