linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [bug report] Input: elants_i2c - add support for eKTF3624
@ 2021-01-28  9:57 Dan Carpenter
  2021-01-28 13:07 ` Michał Mirosław
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2021-01-28  9:57 UTC (permalink / raw)
  To: mirq-linux; +Cc: linux-input

Hello Michał Mirosław,

The patch 9517b95bdc46: "Input: elants_i2c - add support for
eKTF3624" from Jan 24, 2021, leads to the following static checker
warning:

	drivers/input/touchscreen/elants_i2c.c:966 elants_i2c_mt_event()
	warn: should this be a bitwise negate mask?

drivers/input/touchscreen/elants_i2c.c
   942          /* Note: all fingers have the same tool type */
   943          tool_type = buf[FW_POS_TOOL_TYPE] & BIT(0) ?
   944                          MT_TOOL_FINGER : MT_TOOL_PALM;
   945  
   946          for (i = 0; i < MAX_CONTACT_NUM && n_fingers; i++) {
   947                  if (finger_state & 1) {
   948                          unsigned int x, y, p, w;
   949                          u8 *pos;
   950  
   951                          pos = &buf[FW_POS_XY + i * 3];
   952                          x = (((u16)pos[0] & 0xf0) << 4) | pos[1];
   953                          y = (((u16)pos[0] & 0x0f) << 8) | pos[2];
   954  
   955                          /*
   956                           * eKTF3624 may have use "old" touch-report format,
   957                           * depending on a device and TS firmware version.
   958                           * For example, ASUS Transformer devices use the "old"
   959                           * format, while ASUS Nexus 7 uses the "new" formant.
   960                           */
   961                          if (packet_size == PACKET_SIZE_OLD &&
   962                              ts->chip_id == EKTF3624) {
   963                                  w = buf[FW_POS_WIDTH + i / 2];
   964                                  w >>= 4 * (~i & 1);
   965                                  w |= w << 4;
   966                                  w |= !w;
                                        ^^^^^^^^

This code is just very puzzling.  I think it may actually be correct?
The boring and conventional way to write this would be to do it like so:

	if (!w)
		w = 1;

   967                                  p = w;
   968                          } else {
   969                                  p = buf[FW_POS_PRESSURE + i];
   970                                  w = buf[FW_POS_WIDTH + i];
   971                          }
   972  
   973                          dev_dbg(&ts->client->dev, "i=%d x=%d y=%d p=%d w=%d\n",
   974                                  i, x, y, p, w);
   975  
   976                          input_mt_slot(input, i);
   977                          input_mt_report_slot_state(input, tool_type, true);
   978                          touchscreen_report_pos(input, &ts->prop, x, y, true);

regards,
dan carpenter

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

end of thread, other threads:[~2021-01-28 23:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-28  9:57 [bug report] Input: elants_i2c - add support for eKTF3624 Dan Carpenter
2021-01-28 13:07 ` Michał Mirosław
2021-01-28 14:37   ` Dan Carpenter
2021-01-28 23:21     ` Michał Mirosław

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).