power: supply: qti_battery_charger: Fix NULL pointer dereference

With psy initialized in battery_chg_init_psy(), read_property_id()
when called from battery_chg_parse_dt() can try accessing
psy->desc->name when dynamic debugging is enabled. Fix it.

Change-Id: I88114ea9779d5113524b8b15659bf8bafe6364ed
Signed-off-by: Subbaraman Narayanamurthy <quic_subbaram@quicinc.com>
This commit is contained in:
Subbaraman Narayanamurthy 2022-08-25 10:31:08 -07:00 committed by Gerrit - the friendly Code Review server
parent c73b8b29cc
commit 00ad633ef4

View File

@ -396,8 +396,9 @@ static int write_property_id(struct battery_chg_dev *bcdev,
req_msg.hdr.type = MSG_TYPE_REQ_RESP;
req_msg.hdr.opcode = pst->opcode_set;
pr_debug("psy: %s prop_id: %u val: %u\n", pst->psy->desc->name,
req_msg.property_id, val);
if (pst->psy)
pr_debug("psy: %s prop_id: %u val: %u\n", pst->psy->desc->name,
req_msg.property_id, val);
return battery_chg_write(bcdev, &req_msg, sizeof(req_msg));
}
@ -414,8 +415,9 @@ static int read_property_id(struct battery_chg_dev *bcdev,
req_msg.hdr.type = MSG_TYPE_REQ_RESP;
req_msg.hdr.opcode = pst->opcode_get;
pr_debug("psy: %s prop_id: %u\n", pst->psy->desc->name,
req_msg.property_id);
if (pst->psy)
pr_debug("psy: %s prop_id: %u\n", pst->psy->desc->name,
req_msg.property_id);
return battery_chg_write(bcdev, &req_msg, sizeof(req_msg));
}
@ -429,8 +431,9 @@ static int get_property_id(struct psy_state *pst,
if (pst->map[i] == prop)
return i;
pr_err("No property id for property %d in psy %s\n", prop,
pst->psy->desc->name);
if (pst->psy)
pr_err("No property id for property %d in psy %s\n", prop,
pst->psy->desc->name);
return -ENOENT;
}