Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp193070img; Mon, 18 Mar 2019 00:35:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqxOb3Y6Bnqkiu2hMNw2fs9dODPhA4WoxYDWwuLKZtXJF0vJ30Ww+d3JiTMu8BBc+RQ/D4NR X-Received: by 2002:a17:902:6b8a:: with SMTP id p10mr18638932plk.109.1552894525357; Mon, 18 Mar 2019 00:35:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552894525; cv=none; d=google.com; s=arc-20160816; b=W4N1C6qQmnGGttmK/HVI3sa2UJJmLy0RKPJsDbstnLH79RdNEH8PmGMz/l9OQ6gMRZ JAqnVq+uiLT90Ov2xuLDPmyAX68zZr6DMFn7ak+YbOLi0We40wYdmYBNnSptRNfYorzc TW9XNLkP4Yl/FIlBvvC/5aVooIPoGnlu5rGvG4klfXSBRUzi+C3QuJCMkGuvcQ1OfxEA 4eVR26DDE4zTxOZMMNbgz9/bEHWWLNlrVAIcUnYF5EaPgUg31XOT1ENiOc2hvpbgq1lL 0SPjtBJ+6vyJnBZTr6g2nPM6EHJSN8rgTCajR4NsT7NQl4YRfHPSRKOzrHZtOd1lpwPp QqpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=t9BeQzfynVKA0dVxQllrOHEDZiZ9NhlimPs6y/jEdwg=; b=T3WHbIeqooOl/mtO/5xntEZbrXfC2OGs9GTQJX99LH09/oC3myw6xohqdgI8QV+Vr7 Ym0h6bsaAHt5uG+w/bXtVTniS1Pg7HtSqgOwjT+RgicTxqi+HHCo/qBwfLD7mVEfbheZ ttOsrgP+d/yfcK9rtlbJ9SlDYu+8HM852UzbqWq55z+YO2hvN28wOjmppfV58XTDD2rw GXuirL4/2Ok2+wtFfn5Zq0grQdH7tqQvC3C1qOaS8rHvnjsnkCTWRaiu/X75iTICaIff xUqPDuNc5fAbURr08z83ZTpSZUd7ETQukNGaOt7ZCrx2lzmaXtzsapGFJLVSPc4W8k0e 4G0A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y18si1241638pfe.72.2019.03.18.00.35.10; Mon, 18 Mar 2019 00:35:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727419AbfCRHeR (ORCPT + 99 others); Mon, 18 Mar 2019 03:34:17 -0400 Received: from mirror2.csie.ntu.edu.tw ([140.112.30.76]:40896 "EHLO wens.csie.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726782AbfCRHeO (ORCPT ); Mon, 18 Mar 2019 03:34:14 -0400 Received: by wens.csie.org (Postfix, from userid 1000) id 06C315FD9F; Mon, 18 Mar 2019 15:34:12 +0800 (CST) From: Chen-Yu Tsai To: Srinivas Kandagatla , Maxime Ripard Cc: linux-sunxi@googlegroups.com, Chen-Yu Tsai , linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/6] nvmem: sunxi_sid: Dynamically allocate nvmem_config structure Date: Mon, 18 Mar 2019 15:33:51 +0800 Message-Id: <20190318073354.12151-4-wens@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190318073354.12151-1-wens@kernel.org> References: <20190318073354.12151-1-wens@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chen-Yu Tsai The sunxi_sid driver currently uses a statically allocated nvmem_config structure that is updated at probe time. This is sub-optimal as it limits the driver to one instance, and also takes up space even if the device is not present. Modify the driver to allocate the nvmem_config structure at probe time, plugging in the desired parameters along the way. Signed-off-by: Chen-Yu Tsai --- drivers/nvmem/sunxi_sid.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/drivers/nvmem/sunxi_sid.c b/drivers/nvmem/sunxi_sid.c index 15fbfab62595..75c1f48cb3d0 100644 --- a/drivers/nvmem/sunxi_sid.c +++ b/drivers/nvmem/sunxi_sid.c @@ -35,13 +35,6 @@ #define SUN8I_SID_OP_LOCK (0xAC << 8) #define SUN8I_SID_READ BIT(1) -static struct nvmem_config econfig = { - .name = "sunxi-sid", - .read_only = true, - .stride = 4, - .word_size = 1, -}; - struct sunxi_sid_cfg { u32 value_offset; u32 size; @@ -150,6 +143,7 @@ static int sunxi_sid_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct resource *res; + struct nvmem_config *nvmem_cfg; struct nvmem_device *nvmem; struct sunxi_sid *sid; int size; @@ -172,14 +166,23 @@ static int sunxi_sid_probe(struct platform_device *pdev) size = cfg->size; - econfig.size = size; - econfig.dev = dev; + nvmem_cfg = devm_kzalloc(dev, sizeof(*nvmem_cfg), GFP_KERNEL); + if (!nvmem_cfg) + return -ENOMEM; + + nvmem_cfg->dev = dev; + nvmem_cfg->name = "sunxi-sid"; + nvmem_cfg->read_only = true; + nvmem_cfg->size = cfg->size; + nvmem_cfg->word_size = 1; + nvmem_cfg->stride = 4; + nvmem_cfg->priv = sid; if (cfg->need_register_readout) - econfig.reg_read = sun8i_sid_read_by_reg; + nvmem_cfg->reg_read = sun8i_sid_read_by_reg; else - econfig.reg_read = sunxi_sid_read; - econfig.priv = sid; - nvmem = devm_nvmem_register(dev, &econfig); + nvmem_cfg->reg_read = sunxi_sid_read; + + nvmem = devm_nvmem_register(dev, nvmem_cfg); if (IS_ERR(nvmem)) return PTR_ERR(nvmem); @@ -187,8 +190,7 @@ static int sunxi_sid_probe(struct platform_device *pdev) if (!randomness) return -ENOMEM; - econfig.reg_read(sid, 0, randomness, size); - + nvmem_cfg->reg_read(sid, 0, randomness, size); add_device_randomness(randomness, size); kfree(randomness); -- 2.20.1