From nobody Mon Feb 9 10:11:59 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571930573; cv=none; d=zoho.com; s=zohoarc; b=B8L68gbxVqJthtponf88YpbigrQeEZLM6MdzCTxbXso6DlISX7aWwWhqfPTbYOqvnQ6bPCd03ZA2APKMIeg1WuJ5NYiv6R1njDyf0VGgpT+oR0uOI4ngEdAQfwbMGFgvZ6xi2rLHeGDKrHnWiB73SBCqC4jFwWE6RmZaLMu9bRQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571930573; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nbdM4QsVX6w/vZF6SHA0C1caqBfc8BftNTLt4pHDGbQ=; b=Ch+PGdUO7Ge2VevRYHhhHxg8a0lraWSXmy62FuVlYu5pOV4E9GZTBv361zxOvO3bxLrjxVCbx6sdc7+VIgTFuR4qksUDblufinTZc2E8i2wQwhfpWh+rBAyVUclP8yY678f/8i0fB3H3uQ1V8CQWw91bpIUTrIAsMGgXpnoQ0Qo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571930573173813.5919053563886; Thu, 24 Oct 2019 08:22:53 -0700 (PDT) Received: from localhost ([::1]:45302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNewp-0005OE-Nk for importer@patchew.org; Thu, 24 Oct 2019 11:22:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34825) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNdiy-0007ry-Lh for qemu-devel@nongnu.org; Thu, 24 Oct 2019 10:04:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNdit-0007ih-At for qemu-devel@nongnu.org; Thu, 24 Oct 2019 10:04:24 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]:53281) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iNdir-0007hQ-OI for qemu-devel@nongnu.org; Thu, 24 Oct 2019 10:04:18 -0400 Received: by mail-wm1-x32a.google.com with SMTP id n7so2166733wmc.3 for ; Thu, 24 Oct 2019 07:04:16 -0700 (PDT) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id b7sm10610155wrn.53.2019.10.24.07.04.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Oct 2019 07:04:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nbdM4QsVX6w/vZF6SHA0C1caqBfc8BftNTLt4pHDGbQ=; b=d6heQ/OBpiVsx1ecilCPT+HUeoAdccwTZUdXs0eAT//BB9MAAL3NzqsWe8p/rFAwkm 4gNQWW4N2VL5S8CpmYZqjdAiJGbt6RYyqZQZqI20oiL0YAqClvyVRwHU1rbl7voyX8RL fMWh2w1LvvYVZtF+C8G6N/DiXHC/lZIFamSNcZmlaOA4kqn0NxONoJynF5IuaQD/IHaP JfQi5apBa/8GZdf0PuUnm3AI8TzceISZ7AbyXSDbE9Tp12lIGZoXvIrETsPF/pm5XJzj 8EQXB1iELmwVJiZ6c1T8cYPClSa6E4s3zBF+LNYUzv62qqKlcEGH0Yic2WxrUdLRCSdt bOjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=nbdM4QsVX6w/vZF6SHA0C1caqBfc8BftNTLt4pHDGbQ=; b=FGyVzSqzuSCQxWmv+QKCmBw/tSyYVA84WR9aKpO2MI2UjE+jvGv9wH1EqPjtq9OciT bIfD5jRGeIjS4Etbu0MPp7rRsV17TjJwTXYSnaY/ksjrNIT+ZyoMRexPnPi+WMwTsZq5 tEwoQjcPLGNZSQ7MfVamNhNUtf2GWcL8Gb/JfjFaWyadlSWd4SSqMPcLxeeax15nH4ZI Ubk3mQO6MdjUVMe1p891CSkPinoo5wPX7jyXb1XZVWcMsPzDYGx0mqFAIkMN74eMPHe0 gfTEaUmECx73/ZwORlY0tqiwbTUpqSF59bCTlGbGdHI/SRrK3BcbHbGtlccZBhUUksIR ZI7Q== X-Gm-Message-State: APjAAAU7pu0wZob2cJRLZuiVXkO9dAneVtoz0zkrQUvLKalEwCqMQX4J 1NSrPWE8Qm8udkDUvbvLZBhCQbzr X-Google-Smtp-Source: APXvYqw7/VeX3i9cgxJ9iiNHwbF3RFDBrDwZ222FLJnkpUPZHsdovMjryKNglHUFm7zPnz9QkrJTSg== X-Received: by 2002:a1c:6386:: with SMTP id x128mr4994980wmb.41.1571925855227; Thu, 24 Oct 2019 07:04:15 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 16/39] fw_cfg: add "modify" functions for all types Date: Thu, 24 Oct 2019 16:03:32 +0200 Message-Id: <1571925835-31930-17-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1571925835-31930-1-git-send-email-pbonzini@redhat.com> References: <1571925835-31930-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32a X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sergio Lopez Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Sergio Lopez This allows to alter the contents of an already added item. Signed-off-by: Sergio Lopez Reviewed-by: Michael S. Tsirkin Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/nvram/fw_cfg.c | 29 +++++++++++++++++++++++++++++ include/hw/nvram/fw_cfg.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index 7dc3ac3..aef1727 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -690,6 +690,15 @@ void fw_cfg_add_string(FWCfgState *s, uint16_t key, co= nst char *value) fw_cfg_add_bytes(s, key, g_memdup(value, sz), sz); } =20 +void fw_cfg_modify_string(FWCfgState *s, uint16_t key, const char *value) +{ + size_t sz =3D strlen(value) + 1; + char *old; + + old =3D fw_cfg_modify_bytes_read(s, key, g_memdup(value, sz), sz); + g_free(old); +} + void fw_cfg_add_i16(FWCfgState *s, uint16_t key, uint16_t value) { uint16_t *copy; @@ -720,6 +729,16 @@ void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint3= 2_t value) fw_cfg_add_bytes(s, key, copy, sizeof(value)); } =20 +void fw_cfg_modify_i32(FWCfgState *s, uint16_t key, uint32_t value) +{ + uint32_t *copy, *old; + + copy =3D g_malloc(sizeof(value)); + *copy =3D cpu_to_le32(value); + old =3D fw_cfg_modify_bytes_read(s, key, copy, sizeof(value)); + g_free(old); +} + void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value) { uint64_t *copy; @@ -730,6 +749,16 @@ void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint6= 4_t value) fw_cfg_add_bytes(s, key, copy, sizeof(value)); } =20 +void fw_cfg_modify_i64(FWCfgState *s, uint16_t key, uint64_t value) +{ + uint64_t *copy, *old; + + copy =3D g_malloc(sizeof(value)); + *copy =3D cpu_to_le64(value); + old =3D fw_cfg_modify_bytes_read(s, key, copy, sizeof(value)); + g_free(old); +} + void fw_cfg_set_order_override(FWCfgState *s, int order) { assert(s->fw_cfg_order_override =3D=3D 0); diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h index 80e435d..b5291ee 100644 --- a/include/hw/nvram/fw_cfg.h +++ b/include/hw/nvram/fw_cfg.h @@ -99,6 +99,20 @@ void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void = *data, size_t len); void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value); =20 /** + * fw_cfg_modify_string: + * @s: fw_cfg device being modified + * @key: selector key value for new fw_cfg item + * @value: NUL-terminated ascii string + * + * Replace the fw_cfg item available by selecting the given key. The new + * data will consist of a dynamically allocated copy of the provided strin= g, + * including its NUL terminator. The data being replaced, assumed to have + * been dynamically allocated during an earlier call to either + * fw_cfg_add_string() or fw_cfg_modify_string(), is freed before returnin= g. + */ +void fw_cfg_modify_string(FWCfgState *s, uint16_t key, const char *value); + +/** * fw_cfg_add_i16: * @s: fw_cfg device being modified * @key: selector key value for new fw_cfg item @@ -137,6 +151,20 @@ void fw_cfg_modify_i16(FWCfgState *s, uint16_t key, ui= nt16_t value); void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint32_t value); =20 /** + * fw_cfg_modify_i32: + * @s: fw_cfg device being modified + * @key: selector key value for new fw_cfg item + * @value: 32-bit integer + * + * Replace the fw_cfg item available by selecting the given key. The new + * data will consist of a dynamically allocated copy of the given 32-bit + * value, converted to little-endian representation. The data being replac= ed, + * assumed to have been dynamically allocated during an earlier call to + * either fw_cfg_add_i32() or fw_cfg_modify_i32(), is freed before returni= ng. + */ +void fw_cfg_modify_i32(FWCfgState *s, uint16_t key, uint32_t value); + +/** * fw_cfg_add_i64: * @s: fw_cfg device being modified * @key: selector key value for new fw_cfg item @@ -149,6 +177,20 @@ void fw_cfg_add_i32(FWCfgState *s, uint16_t key, uint3= 2_t value); void fw_cfg_add_i64(FWCfgState *s, uint16_t key, uint64_t value); =20 /** + * fw_cfg_modify_i64: + * @s: fw_cfg device being modified + * @key: selector key value for new fw_cfg item + * @value: 64-bit integer + * + * Replace the fw_cfg item available by selecting the given key. The new + * data will consist of a dynamically allocated copy of the given 64-bit + * value, converted to little-endian representation. The data being replac= ed, + * assumed to have been dynamically allocated during an earlier call to + * either fw_cfg_add_i64() or fw_cfg_modify_i64(), is freed before returni= ng. + */ +void fw_cfg_modify_i64(FWCfgState *s, uint16_t key, uint64_t value); + +/** * fw_cfg_add_file: * @s: fw_cfg device being modified * @filename: name of new fw_cfg file item --=20 1.8.3.1