linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] drm/dp: Fine-tuning for three function implementations
@ 2017-05-01 16:45 SF Markus Elfring
  2017-05-01 16:46 ` [PATCH 1/4] drm/dp: Use seq_putc() in drm_dp_mst_dump_topology() SF Markus Elfring
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-05-01 16:45 UTC (permalink / raw)
  To: dri-devel, Daniel Vetter, David Airlie, Jani Nikula, Sean Paul
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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(-)

-- 
2.12.2

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] drm/dp: Use seq_putc() in drm_dp_mst_dump_topology()
  2017-05-01 16:45 [PATCH 0/4] drm/dp: Fine-tuning for three function implementations SF Markus Elfring
@ 2017-05-01 16:46 ` SF Markus Elfring
  2017-05-01 17:11   ` Joe Perches
  2017-05-01 16:47 ` [PATCH 2/4] drm/dp: Combine two seq_printf() calls into one call " SF Markus Elfring
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: SF Markus Elfring @ 2017-05-01 16:46 UTC (permalink / raw)
  To: dri-devel, Daniel Vetter, David Airlie, Jani Nikula, Sean Paul
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/gpu/drm/drm_dp_mst_topology.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c b/drivers/gpu/drm/drm_dp_mst_topology.c
index d3fc7e4e85b7..89fc05fa6a74 100644
--- a/drivers/gpu/drm/drm_dp_mst_topology.c
+++ b/drivers/gpu/drm/drm_dp_mst_topology.c
@@ -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');
 		}
 
 	}
-- 
2.12.2

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/4] drm/dp: Combine two seq_printf() calls into one call in drm_dp_mst_dump_topology()
  2017-05-01 16:45 [PATCH 0/4] drm/dp: Fine-tuning for three function implementations SF Markus Elfring
  2017-05-01 16:46 ` [PATCH 1/4] drm/dp: Use seq_putc() in drm_dp_mst_dump_topology() SF Markus Elfring
@ 2017-05-01 16:47 ` SF Markus Elfring
  2017-05-01 16:48 ` [PATCH 3/4] drm/dp: Replace six seq_printf() calls by seq_puts() " SF Markus Elfring
  2017-05-01 16:49 ` [PATCH 4/4] drm/dp: Adjust four checks for null pointers SF Markus Elfring
  3 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-05-01 16:47 UTC (permalink / raw)
  To: dri-devel, Daniel Vetter, David Airlie, Jani Nikula, Sean Paul
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/gpu/drm/drm_dp_mst_topology.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c b/drivers/gpu/drm/drm_dp_mst_topology.c
index 89fc05fa6a74..2ddcb3d2f65a 100644
--- a/drivers/gpu/drm/drm_dp_mst_topology.c
+++ b/drivers/gpu/drm/drm_dp_mst_topology.c
@@ -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: ");
-- 
2.12.2

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/4] drm/dp: Replace six seq_printf() calls by seq_puts() in drm_dp_mst_dump_topology()
  2017-05-01 16:45 [PATCH 0/4] drm/dp: Fine-tuning for three function implementations SF Markus Elfring
  2017-05-01 16:46 ` [PATCH 1/4] drm/dp: Use seq_putc() in drm_dp_mst_dump_topology() SF Markus Elfring
  2017-05-01 16:47 ` [PATCH 2/4] drm/dp: Combine two seq_printf() calls into one call " SF Markus Elfring
@ 2017-05-01 16:48 ` SF Markus Elfring
  2017-05-01 16:49 ` [PATCH 4/4] drm/dp: Adjust four checks for null pointers SF Markus Elfring
  3 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-05-01 16:48 UTC (permalink / raw)
  To: dri-devel, Daniel Vetter, David Airlie, Jani Nikula, Sean Paul
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/gpu/drm/drm_dp_mst_topology.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c b/drivers/gpu/drm/drm_dp_mst_topology.c
index 2ddcb3d2f65a..bcc76f15f1ce 100644
--- a/drivers/gpu/drm/drm_dp_mst_topology.c
+++ b/drivers/gpu/drm/drm_dp_mst_topology.c
@@ -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');
-- 
2.12.2

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 4/4] drm/dp: Adjust four checks for null pointers
  2017-05-01 16:45 [PATCH 0/4] drm/dp: Fine-tuning for three function implementations SF Markus Elfring
                   ` (2 preceding siblings ...)
  2017-05-01 16:48 ` [PATCH 3/4] drm/dp: Replace six seq_printf() calls by seq_puts() " SF Markus Elfring
@ 2017-05-01 16:49 ` SF Markus Elfring
  3 siblings, 0 replies; 6+ messages in thread
From: SF Markus Elfring @ 2017-05-01 16:49 UTC (permalink / raw)
  To: dri-devel, Daniel Vetter, David Airlie, Jani Nikula, Sean Paul
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/gpu/drm/drm_dp_mst_topology.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c b/drivers/gpu/drm/drm_dp_mst_topology.c
index bcc76f15f1ce..f46bf5101d14 100644
--- a/drivers/gpu/drm/drm_dp_mst_topology.c
+++ b/drivers/gpu/drm/drm_dp_mst_topology.c
@@ -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;
 		}
-- 
2.12.2

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/4] drm/dp: Use seq_putc() in drm_dp_mst_dump_topology()
  2017-05-01 16:46 ` [PATCH 1/4] drm/dp: Use seq_putc() in drm_dp_mst_dump_topology() SF Markus Elfring
@ 2017-05-01 17:11   ` Joe Perches
  0 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2017-05-01 17:11 UTC (permalink / raw)
  To: SF Markus Elfring, dri-devel, Daniel Vetter, David Airlie,
	Jani Nikula, Sean Paul
  Cc: LKML, kernel-janitors

On Mon, 2017-05-01 at 18:46 +0200, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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.
[]
> diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c b/drivers/gpu/drm/drm_dp_mst_topology.c
[]
> @@ -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');

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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-05-01 17:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-01 16:45 [PATCH 0/4] drm/dp: Fine-tuning for three function implementations SF Markus Elfring
2017-05-01 16:46 ` [PATCH 1/4] drm/dp: Use seq_putc() in drm_dp_mst_dump_topology() SF Markus Elfring
2017-05-01 17:11   ` Joe Perches
2017-05-01 16:47 ` [PATCH 2/4] drm/dp: Combine two seq_printf() calls into one call " SF Markus Elfring
2017-05-01 16:48 ` [PATCH 3/4] drm/dp: Replace six seq_printf() calls by seq_puts() " SF Markus Elfring
2017-05-01 16:49 ` [PATCH 4/4] drm/dp: Adjust four checks for null pointers SF Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).