Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp39000imm; Tue, 17 Jul 2018 13:30:51 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc6T9KU39h6ABtQRHDn49OSyB6+BJ1156QUUwU6FiJmotZlPlR0tDBrNqT+ZyJyL3hc3VdT X-Received: by 2002:a63:5d58:: with SMTP id o24-v6mr3039842pgm.349.1531859451427; Tue, 17 Jul 2018 13:30:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531859451; cv=none; d=google.com; s=arc-20160816; b=I0nRplyljm38ll0yOp9Dq9VxeWncqzdfxX+EOkaKNVEjly+NjZ7CHM8ixBwqdrQmKM W/baGV/06KRtMLh8hwLQP6olXDRlr+m9jbAQnLpi4kMJG9DvAr5hPjZjSsOKdqjE3/BX DkDv6DEzE9t+Y8OGyhnDBnJZ4em0G3MzhJC41ZyTVcDWXqzAqfPVCeywoICgnanLXlSx ax4XtazKFa4I7gBTVJGIHG9NvmXRRjzRbuPThsLkXjitFO/twwE+F0OWleOYRZDugOR9 kpGOWkUn33qNfKxZ/mvQvbCJ6y2vYDThCsMv4FFR8BRB03PRBQreI+wj2ktWrRiqV/A9 h6OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Eg2Mjkb1M+l5w9+ISrAtsAOrO6qEMIH17I1Pv/SmrYg=; b=Nf+aXKW1GTz8QQgZtp2tL2myIuuehZ3ugfNlPfxdHKLW7yVkaAE2Fp/RMPU9Vm5z4v bfpncW+Khp6yk8B6DqTTk5LyZKcVhVTjv9RoFx5fxcWFVt04vcmhQuBPx5lxO1i9KWnd H8M3UVxHfR5GX/dJ1OjnfcDkplFHzvLFXtRkNtf+a/pX9K/rxCktS9VQ8R8Fd9Z9QXBf Lj7BcAnFL2u4oNDlkSBW1grrlrm50+0vv9oIY8+zRnqEj1L/t1AljUp79WymM1+dzJcI WHpajcyJWlizVffLGBcVv3YtO/tNHSWPtixVjIoDAbx/fKct3zoe2j3DMJtC2bCdJZoo na0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VK8LBw6g; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 61-v6si1671232plf.63.2018.07.17.13.30.36; Tue, 17 Jul 2018 13:30:51 -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; dkim=pass header.i=@chromium.org header.s=google header.b=VK8LBw6g; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730621AbeGQVEM (ORCPT + 99 others); Tue, 17 Jul 2018 17:04:12 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:36298 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730397AbeGQVEK (ORCPT ); Tue, 17 Jul 2018 17:04:10 -0400 Received: by mail-pg1-f195.google.com with SMTP id m19-v6so937113pgv.3 for ; Tue, 17 Jul 2018 13:29:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Eg2Mjkb1M+l5w9+ISrAtsAOrO6qEMIH17I1Pv/SmrYg=; b=VK8LBw6g8slfcZTGaJVYCC4JTRIi/iZm9u74JFt/SaRYZao7EFC4ZHF65IdodSs6Jk yXI4BuYgxUe3dNRfmR+VJ1ggJNb1Xx1XP4WBv5+OoZd4kUgf13QmtF7+vw8uY336I+X2 eZV9aq0LSWGrkXXRtdC6JXKAAIgz7+Q1YoTAA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Eg2Mjkb1M+l5w9+ISrAtsAOrO6qEMIH17I1Pv/SmrYg=; b=S0IyuDO+DA3ToAGqiy7xkVcJwYewr+o2UpjqAkwhD7KS2ApJVhnggEiqYx4pqYu5iZ eNXlHxXp/K4l3Uav5wtSBjX9htFujrpij8zHq3vj+F5rYfj8QrhlnV7u1YPTl1fu269u uzLTlPITBpYFSeZbo/9MxMxmOrIOW1VYnLL9aatyQ95Hl244s/aISGIK8OprA0lJhHg8 QW3b09zYmd8G69xrWbqcstyLoMfBHsiYSBFXcgiDbiiUZK4pU94jMJmjZdKDLgb4W/FR YVkkiWEimTab+yN9heZzGHWuY5dBWl8r0/wNbT5nccEF4dmpk3CfJhPm5XnvdB2AI2Cr Gf2g== X-Gm-Message-State: AOUpUlFETThYtsScSPJwRAYzME4fcSO5wLb1/YzipiZy1Zz96vi58P/0 rpotlJAWdI41kmWmHHsk6Bh79Q== X-Received: by 2002:a63:f804:: with SMTP id n4-v6mr3064902pgh.106.1531859391212; Tue, 17 Jul 2018 13:29:51 -0700 (PDT) Received: from swboyd.mtv.corp.google.com ([2620:0:1000:1511:d30e:62c6:f82c:ff40]) by smtp.gmail.com with ESMTPSA id a20-v6sm2563426pfi.124.2018.07.17.13.29.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jul 2018 13:29:50 -0700 (PDT) From: Stephen Boyd To: Andy Gross Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, Mahesh Sivasubramanian , Lina Iyer , Bjorn Andersson , Evan Green Subject: [PATCH 1/2] soc: qcom: cmd-db: Remove memcpy()ing from cmd_db_get_header() Date: Tue, 17 Jul 2018 13:29:46 -0700 Message-Id: <20180717202947.197922-2-swboyd@chromium.org> X-Mailer: git-send-email 2.18.0.203.gfac676dfb9-goog In-Reply-To: <20180717202947.197922-1-swboyd@chromium.org> References: <20180717202947.197922-1-swboyd@chromium.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The cmd_db_get_header() function is a static local function that doesn't need to copy anything from one place to another. Instead, it can just point into the region by returning pointers to what we're looking for. If we do that, we should mark what we're returning as const so that code can't modify cmd-db without an obvious cast. Cc: Mahesh Sivasubramanian Cc: Lina Iyer Cc: Bjorn Andersson Cc: Evan Green Signed-off-by: Stephen Boyd --- drivers/soc/qcom/cmd-db.c | 60 +++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/drivers/soc/qcom/cmd-db.c b/drivers/soc/qcom/cmd-db.c index a6f646295f06..5c9cc6824891 100644 --- a/drivers/soc/qcom/cmd-db.c +++ b/drivers/soc/qcom/cmd-db.c @@ -101,8 +101,7 @@ static bool cmd_db_magic_matches(const struct cmd_db_header *header) static struct cmd_db_header *cmd_db_header; - -static inline void *rsc_to_entry_header(struct rsc_hdr *hdr) +static inline const void *rsc_to_entry_header(const struct rsc_hdr *hdr) { u16 offset = le16_to_cpu(hdr->header_offset); @@ -110,7 +109,7 @@ static inline void *rsc_to_entry_header(struct rsc_hdr *hdr) } static inline void * -rsc_offset(struct rsc_hdr *hdr, struct entry_header *ent) +rsc_offset(const struct rsc_hdr *hdr, const struct entry_header *ent) { u16 offset = le16_to_cpu(hdr->data_offset); u16 loffset = le16_to_cpu(ent->offset); @@ -134,11 +133,11 @@ int cmd_db_ready(void) } EXPORT_SYMBOL(cmd_db_ready); -static int cmd_db_get_header(const char *id, struct entry_header *eh, - struct rsc_hdr *rh) +static int cmd_db_get_header(const char *id, const struct entry_header **eh, + const struct rsc_hdr **rh) { - struct rsc_hdr *rsc_hdr; - struct entry_header *ent; + const struct rsc_hdr *rsc_hdr; + const struct entry_header *ent; int ret, i, j; u8 query[8]; @@ -146,9 +145,6 @@ static int cmd_db_get_header(const char *id, struct entry_header *eh, if (ret) return ret; - if (!eh || !rh) - return -EINVAL; - /* Pad out query string to same length as in DB */ strncpy(query, id, sizeof(query)); @@ -159,14 +155,13 @@ static int cmd_db_get_header(const char *id, struct entry_header *eh, ent = rsc_to_entry_header(rsc_hdr); for (j = 0; j < le16_to_cpu(rsc_hdr->cnt); j++, ent++) { - if (memcmp(ent->id, query, sizeof(ent->id)) == 0) - break; - } - - if (j < le16_to_cpu(rsc_hdr->cnt)) { - memcpy(eh, ent, sizeof(*ent)); - memcpy(rh, rsc_hdr, sizeof(*rh)); - return 0; + if (memcmp(ent->id, query, sizeof(ent->id)) == 0) { + if (eh) + *eh = ent; + if (rh) + *rh = rsc_hdr; + return 0; + } } } @@ -186,12 +181,11 @@ static int cmd_db_get_header(const char *id, struct entry_header *eh, u32 cmd_db_read_addr(const char *id) { int ret; - struct entry_header ent; - struct rsc_hdr rsc_hdr; + const struct entry_header *ent; - ret = cmd_db_get_header(id, &ent, &rsc_hdr); + ret = cmd_db_get_header(id, &ent, NULL); - return ret < 0 ? 0 : le32_to_cpu(ent.addr); + return ret < 0 ? 0 : le32_to_cpu(ent->addr); } EXPORT_SYMBOL(cmd_db_read_addr); @@ -207,8 +201,8 @@ EXPORT_SYMBOL(cmd_db_read_addr); int cmd_db_read_aux_data(const char *id, u8 *data, size_t len) { int ret; - struct entry_header ent; - struct rsc_hdr rsc_hdr; + const struct entry_header *ent; + const struct rsc_hdr *rsc_hdr; u16 ent_len; if (!data) @@ -218,12 +212,12 @@ int cmd_db_read_aux_data(const char *id, u8 *data, size_t len) if (ret) return ret; - ent_len = le16_to_cpu(ent.len); + ent_len = le16_to_cpu(ent->len); if (len < ent_len) return -EINVAL; len = min_t(u16, ent_len, len); - memcpy(data, rsc_offset(&rsc_hdr, &ent), len); + memcpy(data, rsc_offset(rsc_hdr, ent), len); return len; } @@ -239,12 +233,11 @@ EXPORT_SYMBOL(cmd_db_read_aux_data); size_t cmd_db_read_aux_data_len(const char *id) { int ret; - struct entry_header ent; - struct rsc_hdr rsc_hdr; + const struct entry_header *ent; - ret = cmd_db_get_header(id, &ent, &rsc_hdr); + ret = cmd_db_get_header(id, &ent, NULL); - return ret < 0 ? 0 : le16_to_cpu(ent.len); + return ret < 0 ? 0 : le16_to_cpu(ent->len); } EXPORT_SYMBOL(cmd_db_read_aux_data_len); @@ -258,15 +251,14 @@ EXPORT_SYMBOL(cmd_db_read_aux_data_len); enum cmd_db_hw_type cmd_db_read_slave_id(const char *id) { int ret; - struct entry_header ent; - struct rsc_hdr rsc_hdr; + const struct entry_header *ent; u32 addr; - ret = cmd_db_get_header(id, &ent, &rsc_hdr); + ret = cmd_db_get_header(id, &ent, NULL); if (ret < 0) return CMD_DB_HW_INVALID; - addr = le32_to_cpu(ent.addr); + addr = le32_to_cpu(ent->addr); return (addr >> SLAVE_ID_SHIFT) & SLAVE_ID_MASK; } EXPORT_SYMBOL(cmd_db_read_slave_id); -- Sent by a computer through tubes