Skip to content

Commit 4d3d269

Browse files
jlabundydtor
authored andcommitted
Input: iqs626a - drop unused device node references
Each call to device/fwnode_get_named_child_node() must be matched with a call to fwnode_handle_put() once the corresponding node is no longer in use. This ensures a reference count remains balanced in the case of dynamic device tree support. Currently, the driver never calls fwnode_handle_put(); this patch adds the missing calls. Because fwnode_handle_put() does not take a const *fwnode_handle, the const qualifier is removed across all corresponding *fwnode_handle instances. As part of this change, trackpad channel touch thresholds and ATI base values are now specified under single trackpad channel child nodes. This enhancement moves both properties to scalar values as opposed to arrays, making their types consistent across bindings. Fixes: f1d2809 ("Input: Add support for Azoteq IQS626A") Signed-off-by: Jeff LaBundy <[email protected]> Link: https://lore.kernel.org/r/Y9RQVe/V1Hnw1oly@nixie71 Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent d949624 commit 4d3d269

File tree

1 file changed

+73
-83
lines changed

1 file changed

+73
-83
lines changed

drivers/input/misc/iqs626a.c

Lines changed: 73 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -458,18 +458,15 @@ struct iqs626_private {
458458

459459
static noinline_for_stack int
460460
iqs626_parse_events(struct iqs626_private *iqs626,
461-
const struct fwnode_handle *ch_node,
462-
enum iqs626_ch_id ch_id)
461+
struct fwnode_handle *ch_node, enum iqs626_ch_id ch_id)
463462
{
464463
struct iqs626_sys_reg *sys_reg = &iqs626->sys_reg;
465464
struct i2c_client *client = iqs626->client;
466-
const struct fwnode_handle *ev_node;
465+
struct fwnode_handle *ev_node;
467466
const char *ev_name;
468467
u8 *thresh, *hyst;
469-
unsigned int thresh_tp[IQS626_NUM_CH_TP_3];
470468
unsigned int val;
471-
int num_ch = iqs626_channels[ch_id].num_ch;
472-
int error, i, j;
469+
int i;
473470

474471
switch (ch_id) {
475472
case IQS626_CH_ULP_0:
@@ -509,7 +506,7 @@ iqs626_parse_events(struct iqs626_private *iqs626,
509506
* Trackpad touch events are simply described under the
510507
* trackpad child node.
511508
*/
512-
ev_node = ch_node;
509+
ev_node = fwnode_handle_get(ch_node);
513510
} else {
514511
ev_name = iqs626_events[i].name;
515512
ev_node = fwnode_get_named_child_node(ch_node, ev_name);
@@ -533,6 +530,7 @@ iqs626_parse_events(struct iqs626_private *iqs626,
533530
dev_err(&client->dev,
534531
"Invalid input type: %u\n",
535532
val);
533+
fwnode_handle_put(ev_node);
536534
return -EINVAL;
537535
}
538536

@@ -547,6 +545,7 @@ iqs626_parse_events(struct iqs626_private *iqs626,
547545
dev_err(&client->dev,
548546
"Invalid %s channel hysteresis: %u\n",
549547
fwnode_get_name(ch_node), val);
548+
fwnode_handle_put(ev_node);
550549
return -EINVAL;
551550
}
552551

@@ -567,56 +566,31 @@ iqs626_parse_events(struct iqs626_private *iqs626,
567566
dev_err(&client->dev,
568567
"Invalid %s channel threshold: %u\n",
569568
fwnode_get_name(ch_node), val);
569+
fwnode_handle_put(ev_node);
570570
return -EINVAL;
571571
}
572572

573573
if (ch_id == IQS626_CH_HALL)
574574
*thresh = val;
575575
else
576576
*(thresh + iqs626_events[i].th_offs) = val;
577-
578-
continue;
579-
}
580-
581-
if (!fwnode_property_present(ev_node, "azoteq,thresh"))
582-
continue;
583-
584-
error = fwnode_property_read_u32_array(ev_node, "azoteq,thresh",
585-
thresh_tp, num_ch);
586-
if (error) {
587-
dev_err(&client->dev,
588-
"Failed to read %s channel thresholds: %d\n",
589-
fwnode_get_name(ch_node), error);
590-
return error;
591577
}
592578

593-
for (j = 0; j < num_ch; j++) {
594-
if (thresh_tp[j] > IQS626_CHx_THRESH_MAX) {
595-
dev_err(&client->dev,
596-
"Invalid %s channel threshold: %u\n",
597-
fwnode_get_name(ch_node), thresh_tp[j]);
598-
return -EINVAL;
599-
}
600-
601-
sys_reg->tp_grp_reg.ch_reg_tp[j].thresh = thresh_tp[j];
602-
}
579+
fwnode_handle_put(ev_node);
603580
}
604581

605582
return 0;
606583
}
607584

608585
static noinline_for_stack int
609586
iqs626_parse_ati_target(struct iqs626_private *iqs626,
610-
const struct fwnode_handle *ch_node,
611-
enum iqs626_ch_id ch_id)
587+
struct fwnode_handle *ch_node, enum iqs626_ch_id ch_id)
612588
{
613589
struct iqs626_sys_reg *sys_reg = &iqs626->sys_reg;
614590
struct i2c_client *client = iqs626->client;
615-
unsigned int ati_base[IQS626_NUM_CH_TP_3];
616591
unsigned int val;
617592
u8 *ati_target;
618-
int num_ch = iqs626_channels[ch_id].num_ch;
619-
int error, i;
593+
int i;
620594

621595
switch (ch_id) {
622596
case IQS626_CH_ULP_0:
@@ -683,40 +657,13 @@ iqs626_parse_ati_target(struct iqs626_private *iqs626,
683657

684658
*ati_target &= ~IQS626_CHx_ATI_BASE_MASK;
685659
*ati_target |= val;
686-
687-
return 0;
688-
}
689-
690-
if (!fwnode_property_present(ch_node, "azoteq,ati-base"))
691-
return 0;
692-
693-
error = fwnode_property_read_u32_array(ch_node, "azoteq,ati-base",
694-
ati_base, num_ch);
695-
if (error) {
696-
dev_err(&client->dev,
697-
"Failed to read %s channel ATI bases: %d\n",
698-
fwnode_get_name(ch_node), error);
699-
return error;
700-
}
701-
702-
for (i = 0; i < num_ch; i++) {
703-
if (ati_base[i] < IQS626_TPx_ATI_BASE_MIN ||
704-
ati_base[i] > IQS626_TPx_ATI_BASE_MAX) {
705-
dev_err(&client->dev,
706-
"Invalid %s channel ATI base: %u\n",
707-
fwnode_get_name(ch_node), ati_base[i]);
708-
return -EINVAL;
709-
}
710-
711-
ati_base[i] -= IQS626_TPx_ATI_BASE_MIN;
712-
sys_reg->tp_grp_reg.ch_reg_tp[i].ati_base = ati_base[i];
713660
}
714661

715662
return 0;
716663
}
717664

718665
static int iqs626_parse_pins(struct iqs626_private *iqs626,
719-
const struct fwnode_handle *ch_node,
666+
struct fwnode_handle *ch_node,
720667
const char *propname, u8 *enable)
721668
{
722669
struct i2c_client *client = iqs626->client;
@@ -764,13 +711,14 @@ static int iqs626_parse_pins(struct iqs626_private *iqs626,
764711
}
765712

766713
static int iqs626_parse_trackpad(struct iqs626_private *iqs626,
767-
const struct fwnode_handle *ch_node)
714+
struct fwnode_handle *ch_node,
715+
enum iqs626_ch_id ch_id)
768716
{
769717
struct iqs626_sys_reg *sys_reg = &iqs626->sys_reg;
770718
struct i2c_client *client = iqs626->client;
771719
u8 *hyst = &sys_reg->tp_grp_reg.hyst;
720+
int error, count, i;
772721
unsigned int val;
773-
int error, count;
774722

775723
if (!fwnode_property_read_u32(ch_node, "azoteq,lta-update", &val)) {
776724
if (val > IQS626_MISC_A_TPx_LTA_UPDATE_MAX) {
@@ -823,6 +771,48 @@ static int iqs626_parse_trackpad(struct iqs626_private *iqs626,
823771
*hyst |= (val << IQS626_FILT_STR_LP_TPx_SHIFT);
824772
}
825773

774+
for (i = 0; i < iqs626_channels[ch_id].num_ch; i++) {
775+
u8 *ati_base = &sys_reg->tp_grp_reg.ch_reg_tp[i].ati_base;
776+
u8 *thresh = &sys_reg->tp_grp_reg.ch_reg_tp[i].thresh;
777+
struct fwnode_handle *tc_node;
778+
char tc_name[10];
779+
780+
snprintf(tc_name, sizeof(tc_name), "channel-%d", i);
781+
782+
tc_node = fwnode_get_named_child_node(ch_node, tc_name);
783+
if (!tc_node)
784+
continue;
785+
786+
if (!fwnode_property_read_u32(tc_node, "azoteq,ati-base",
787+
&val)) {
788+
if (val < IQS626_TPx_ATI_BASE_MIN ||
789+
val > IQS626_TPx_ATI_BASE_MAX) {
790+
dev_err(&client->dev,
791+
"Invalid %s %s ATI base: %u\n",
792+
fwnode_get_name(ch_node), tc_name, val);
793+
fwnode_handle_put(tc_node);
794+
return -EINVAL;
795+
}
796+
797+
*ati_base = val - IQS626_TPx_ATI_BASE_MIN;
798+
}
799+
800+
if (!fwnode_property_read_u32(tc_node, "azoteq,thresh",
801+
&val)) {
802+
if (val > IQS626_CHx_THRESH_MAX) {
803+
dev_err(&client->dev,
804+
"Invalid %s %s threshold: %u\n",
805+
fwnode_get_name(ch_node), tc_name, val);
806+
fwnode_handle_put(tc_node);
807+
return -EINVAL;
808+
}
809+
810+
*thresh = val;
811+
}
812+
813+
fwnode_handle_put(tc_node);
814+
}
815+
826816
if (!fwnode_property_present(ch_node, "linux,keycodes"))
827817
return 0;
828818

@@ -889,8 +879,7 @@ static int iqs626_parse_trackpad(struct iqs626_private *iqs626,
889879

890880
static noinline_for_stack int
891881
iqs626_parse_channel(struct iqs626_private *iqs626,
892-
const struct fwnode_handle *ch_node,
893-
enum iqs626_ch_id ch_id)
882+
struct fwnode_handle *ch_node, enum iqs626_ch_id ch_id)
894883
{
895884
struct iqs626_sys_reg *sys_reg = &iqs626->sys_reg;
896885
struct i2c_client *client = iqs626->client;
@@ -924,6 +913,20 @@ iqs626_parse_channel(struct iqs626_private *iqs626,
924913
return -EINVAL;
925914
}
926915

916+
error = iqs626_parse_ati_target(iqs626, ch_node, ch_id);
917+
if (error)
918+
return error;
919+
920+
error = iqs626_parse_events(iqs626, ch_node, ch_id);
921+
if (error)
922+
return error;
923+
924+
if (!fwnode_property_present(ch_node, "azoteq,ati-exclude"))
925+
sys_reg->redo_ati |= iqs626_channels[ch_id].active;
926+
927+
if (!fwnode_property_present(ch_node, "azoteq,reseed-disable"))
928+
sys_reg->reseed |= iqs626_channels[ch_id].active;
929+
927930
*engine |= IQS626_CHx_ENG_0_MEAS_CAP_SIZE;
928931
if (fwnode_property_present(ch_node, "azoteq,meas-cap-decrease"))
929932
*engine &= ~IQS626_CHx_ENG_0_MEAS_CAP_SIZE;
@@ -1057,7 +1060,7 @@ iqs626_parse_channel(struct iqs626_private *iqs626,
10571060
*(engine + 1) |= IQS626_CHx_ENG_1_ATI_BAND_TIGHTEN;
10581061

10591062
if (ch_id == IQS626_CH_TP_2 || ch_id == IQS626_CH_TP_3)
1060-
return iqs626_parse_trackpad(iqs626, ch_node);
1063+
return iqs626_parse_trackpad(iqs626, ch_node, ch_id);
10611064

10621065
if (ch_id == IQS626_CH_ULP_0) {
10631066
sys_reg->ch_reg_ulp.hyst &= ~IQS626_ULP_PROJ_ENABLE;
@@ -1378,23 +1381,10 @@ static int iqs626_parse_prop(struct iqs626_private *iqs626)
13781381
continue;
13791382

13801383
error = iqs626_parse_channel(iqs626, ch_node, i);
1384+
fwnode_handle_put(ch_node);
13811385
if (error)
13821386
return error;
13831387

1384-
error = iqs626_parse_ati_target(iqs626, ch_node, i);
1385-
if (error)
1386-
return error;
1387-
1388-
error = iqs626_parse_events(iqs626, ch_node, i);
1389-
if (error)
1390-
return error;
1391-
1392-
if (!fwnode_property_present(ch_node, "azoteq,ati-exclude"))
1393-
sys_reg->redo_ati |= iqs626_channels[i].active;
1394-
1395-
if (!fwnode_property_present(ch_node, "azoteq,reseed-disable"))
1396-
sys_reg->reseed |= iqs626_channels[i].active;
1397-
13981388
sys_reg->active |= iqs626_channels[i].active;
13991389
}
14001390

0 commit comments

Comments
 (0)