Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2e84872a authored by Hemant Kumar's avatar Hemant Kumar Committed by Gerrit - the friendly Code Review server
Browse files

usb: gadget: u_ether: Add NULL check in helper APIs



APIs being called as part of configfs attributes require
to have NULL check for network device pointer. As user
can call show and store call back even if network device
is not allocated which results in to NULL pointer dereference.

For example: In non-NCM composition user tries
cat config/usb_gadget/g1/functions/ncm.0/ifname

Change-Id: Ia4a1c6bec6d20e41886c952b0365419f2a8effcb
Signed-off-by: default avatarHemant Kumar <hemantk@codeaurora.org>
parent 7f5a4774
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -1073,6 +1073,9 @@ int gether_set_dev_addr(struct net_device *net, const char *dev_addr)
	struct eth_dev *dev;
	u8 new_addr[ETH_ALEN];

	if (!net)
		return -ENODEV;

	dev = netdev_priv(net);
	if (get_ether_addr(dev_addr, new_addr))
		return -EINVAL;
@@ -1085,6 +1088,9 @@ int gether_get_dev_addr(struct net_device *net, char *dev_addr, int len)
{
	struct eth_dev *dev;

	if (!net)
		return -ENODEV;

	dev = netdev_priv(net);
	return get_ether_addr_str(dev->dev_mac, dev_addr, len);
}
@@ -1095,6 +1101,9 @@ int gether_set_host_addr(struct net_device *net, const char *host_addr)
	struct eth_dev *dev;
	u8 new_addr[ETH_ALEN];

	if (!net)
		return -ENODEV;

	dev = netdev_priv(net);
	if (get_ether_addr(host_addr, new_addr))
		return -EINVAL;
@@ -1107,6 +1116,9 @@ int gether_get_host_addr(struct net_device *net, char *host_addr, int len)
{
	struct eth_dev *dev;

	if (!net)
		return -ENODEV;

	dev = netdev_priv(net);
	return get_ether_addr_str(dev->host_mac, host_addr, len);
}
@@ -1139,6 +1151,9 @@ void gether_set_qmult(struct net_device *net, unsigned qmult)
{
	struct eth_dev *dev;

	if (!net)
		return;

	dev = netdev_priv(net);
	dev->qmult = qmult;
}
@@ -1148,6 +1163,9 @@ unsigned gether_get_qmult(struct net_device *net)
{
	struct eth_dev *dev;

	if (!net)
		return -ENODEV;

	dev = netdev_priv(net);
	return dev->qmult;
}
@@ -1155,6 +1173,9 @@ EXPORT_SYMBOL_GPL(gether_get_qmult);

int gether_get_ifname(struct net_device *net, char *name, int len)
{
	if (!net)
		return -ENODEV;

	rtnl_lock();
	strlcpy(name, netdev_name(net), len);
	rtnl_unlock();