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

Commit e29fd1a6 authored by Meng Wang's avatar Meng Wang
Browse files

ASoc: soundwire: add null check before using map



Pointer map returned from dev_get_name may be null.
Add null check before derefering.

CRs-Fixed: 985337
Change-Id: I952ae63e9b909dde763b3024d90fe4553e852860
Signed-off-by: default avatarMeng Wang <mwang@codeaurora.org>
parent b65b7cae
Loading
Loading
Loading
Loading
+20 −5
Original line number Diff line number Diff line
/*
 * Copyright (c) 2015, The Linux Foundation. All rights reserved.
 * Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -68,10 +68,10 @@ static int regmap_swr_raw_multi_reg_write(void *context, const void *data,
	struct device *dev = context;
	struct swr_device *swr = to_swr_device(dev);
	struct regmap *map = dev_get_regmap(dev, NULL);
	size_t addr_bytes = map->format.reg_bytes;
	size_t val_bytes = map->format.val_bytes;
	size_t pad_bytes = map->format.pad_bytes;
	size_t num_regs = (count / (addr_bytes + val_bytes + pad_bytes));
	size_t addr_bytes;
	size_t val_bytes;
	size_t pad_bytes;
	size_t num_regs;
	int i = 0;
	int ret = 0;
	u16 *reg;
@@ -83,6 +83,21 @@ static int regmap_swr_raw_multi_reg_write(void *context, const void *data,
		return -EINVAL;
	}

	if (map == NULL) {
		dev_err(dev, "%s: regmap is NULL\n", __func__);
		return -EINVAL;
	}

	addr_bytes = map->format.reg_bytes;
	val_bytes = map->format.val_bytes;
	pad_bytes = map->format.pad_bytes;

	if (addr_bytes + val_bytes + pad_bytes == 0) {
		dev_err(dev, "%s: sum of addr, value and pad is 0\n", __func__);
		return -EINVAL;
	}
	num_regs = count / (addr_bytes + val_bytes + pad_bytes);

	reg = kcalloc(num_regs, sizeof(u16), GFP_KERNEL);
	if (!reg)
		return -ENOMEM;