linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Martin Kepplinger <martink@posteo.de>
Cc: Dixit Parmar <dixitparmar19@gmail.com>,
	Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>,
	Matthias Fend <matthias.fend@wolfvision.net>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 5/8] Input: st1232 - do not allocate fingers data separately
Date: Tue, 22 Oct 2019 12:56:19 -0700	[thread overview]
Message-ID: <20191022195622.66976-6-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20191022195622.66976-1-dmitry.torokhov@gmail.com>

The finger structure size is quite small and allocating it together with
the main driver structure will not increase likelihood of allocation
failing, but reduces number of objects needing to be tracked by the
allocator and devm.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

 drivers/input/touchscreen/st1232.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/input/touchscreen/st1232.c b/drivers/input/touchscreen/st1232.c
index bfea02202ded..dfc0c6cb0213 100644
--- a/drivers/input/touchscreen/st1232.c
+++ b/drivers/input/touchscreen/st1232.c
@@ -50,12 +50,12 @@ struct st1232_ts_data {
 	const struct st_chip_info *chip_info;
 	int read_buf_len;
 	u8 *read_buf;
-	struct st1232_ts_finger *finger;
+	struct st1232_ts_finger fingers[];
 };
 
 static int st1232_ts_read_data(struct st1232_ts_data *ts)
 {
-	struct st1232_ts_finger *finger = ts->finger;
+	struct st1232_ts_finger *finger = ts->fingers;
 	struct i2c_client *client = ts->client;
 	u8 start_reg = ts->chip_info->start_reg;
 	struct i2c_msg msg[] = {
@@ -98,7 +98,7 @@ static int st1232_ts_read_data(struct st1232_ts_data *ts)
 static irqreturn_t st1232_ts_irq_handler(int irq, void *dev_id)
 {
 	struct st1232_ts_data *ts = dev_id;
-	struct st1232_ts_finger *finger = ts->finger;
+	struct st1232_ts_finger *finger = ts->fingers;
 	struct input_dev *input_dev = ts->input_dev;
 	int count = 0;
 	int i, ret;
@@ -177,7 +177,6 @@ static int st1232_ts_probe(struct i2c_client *client,
 {
 	const struct st_chip_info *match;
 	struct st1232_ts_data *ts;
-	struct st1232_ts_finger *finger;
 	struct input_dev *input_dev;
 	int error;
 
@@ -199,16 +198,13 @@ static int st1232_ts_probe(struct i2c_client *client,
 		return -EINVAL;
 	}
 
-	ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL);
+	ts = devm_kzalloc(&client->dev,
+			  struct_size(ts, fingers, match->max_fingers),
+			  GFP_KERNEL);
 	if (!ts)
 		return -ENOMEM;
 
 	ts->chip_info = match;
-	ts->finger = devm_kcalloc(&client->dev,
-				  ts->chip_info->max_fingers, sizeof(*finger),
-				  GFP_KERNEL);
-	if (!ts->finger)
-		return -ENOMEM;
 
 	/* allocate a buffer according to the number of registers to read */
 	ts->read_buf_len = ts->chip_info->max_fingers * 4;
-- 
2.23.0.866.gb869b98d4c-goog


  parent reply	other threads:[~2019-10-22 19:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-22 19:56 [PATCH 0/8] Face lift for st1232 touchscreen driver Dmitry Torokhov
2019-10-22 19:56 ` [PATCH 1/8] Input: st1232 - simplify parsing of read buffer Dmitry Torokhov
2019-10-22 19:56 ` [PATCH 2/8] Input: st1232 - do not unconditionally configure as wakeup source Dmitry Torokhov
2019-10-22 19:56 ` [PATCH 3/8] Input: st1232 - rely on I2C core to configure wakeup interrupt Dmitry Torokhov
2019-10-22 19:56 ` [PATCH 4/8] Input: st1232 - do not reset the chip too early Dmitry Torokhov
2019-10-22 19:56 ` Dmitry Torokhov [this message]
2019-10-22 19:56 ` [PATCH 6/8] Input: st1232 - do not set parent device explicitly Dmitry Torokhov
2019-10-22 19:56 ` [PATCH 7/8] Input: st1232 - note that the receive buffer is DMA-safe Dmitry Torokhov
2019-10-22 19:56 ` [PATCH 8/8] Input: st1232 - switch to using MT-B protocol Dmitry Torokhov
2019-10-28  7:28 ` AW: [PATCH 0/8] Face lift for st1232 touchscreen driver Matthias Fend
2019-10-29  4:09   ` Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191022195622.66976-6-dmitry.torokhov@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=dixitparmar19@gmail.com \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martink@posteo.de \
    --cc=matthias.fend@wolfvision.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).