From patchwork Mon Sep 24 18:33:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 11681 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 0BF6823E57 for ; Mon, 24 Sep 2012 18:33:21 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id A3FABA18F2F for ; Mon, 24 Sep 2012 18:33:20 +0000 (UTC) Received: by ieje10 with SMTP id e10so10800287iej.11 for ; Mon, 24 Sep 2012 11:33:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=XIb9zXdWmSXrugSOtP6XwEEDl6YCdyzaTzA0xDmutB0=; b=Oc58B81eZ/X8wLerMelDjyfBnhTxWX51NlV2ZMIaPF+kz9XdoyUqIlZZznmiCn1PrU alhRElnyOEzKexlbT+jYuIjuuzI5hJyG8WRamuXoz4FmEIv+UKPhyAeevhLgyrH/j7np j3EyGbBoJmwtUUyHecObd7MFBYGOleuMZvR9VA1MgkN0Iw96C5OjasRnEqfC8CoeFQcy 0o56Mc4dYSqEWlh//pGaLyf73it2fhdHkRI3s1Bh/q6uBy7zBRifVw1H4jz3W3JrkBPU pD5Bo4OTf5v4hlaBCsbtUFKYBNRgIRgU9CZiwAugn1Jq1RQ7BLMVC1uqNXTv46SUHtJO I8Gw== Received: by 10.50.217.229 with SMTP id pb5mr6072780igc.28.1348511600106; Mon, 24 Sep 2012 11:33:20 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp257081igc; Mon, 24 Sep 2012 11:33:18 -0700 (PDT) Received: by 10.180.105.6 with SMTP id gi6mr16143049wib.4.1348511597314; Mon, 24 Sep 2012 11:33:17 -0700 (PDT) Received: from mnementh.archaic.org.uk (1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id db1si19656077wib.8.2012.09.24.11.33.16 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 24 Sep 2012 11:33:17 -0700 (PDT) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Authentication-Results: mx.google.com; spf=neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1TGDT1-0003TU-OH; Mon, 24 Sep 2012 19:33:15 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org Subject: [PATCH 3/4] hw/ds1338: Remove 'now' field from state struct Date: Mon, 24 Sep 2012 19:33:14 +0100 Message-Id: <1348511595-13327-4-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1348511595-13327-1-git-send-email-peter.maydell@linaro.org> References: <1348511595-13327-1-git-send-email-peter.maydell@linaro.org> X-Gm-Message-State: ALoCoQm1AnRvfJ8w3F4l0wexpohJv/V1a7SAbeBAf6KD2aImvI4MxxuGtiTsu1KaIG0fKZsV9Jn5 The 'struct tm now' field in the state structure is in fact only ever used as a temporary (the actual RTC state is held in 'offset'). Remove it from the state structure in favour of using local variables to avoid confusion about whether it needs to be saved on migration. Signed-off-by: Peter Maydell --- hw/ds1338.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/hw/ds1338.c b/hw/ds1338.c index 842d2de..16aba4b 100644 --- a/hw/ds1338.c +++ b/hw/ds1338.c @@ -20,7 +20,6 @@ typedef struct { I2CSlave i2c; time_t offset; - struct tm now; uint8_t nvram[NVRAM_SIZE]; int ptr; int addr_byte; @@ -31,21 +30,22 @@ static void capture_current_time(DS1338State *s) /* Capture the current time into the secondary registers * which will be actually read by the data transfer operation. */ - qemu_get_timedate(&s->now, s->offset); - s->nvram[0] = to_bcd(s->now.tm_sec); - s->nvram[1] = to_bcd(s->now.tm_min); + struct tm now; + qemu_get_timedate(&now, s->offset); + s->nvram[0] = to_bcd(now.tm_sec); + s->nvram[1] = to_bcd(now.tm_min); if (s->nvram[2] & 0x40) { - s->nvram[2] = (to_bcd((s->now.tm_hour % 12)) + 1) | 0x40; - if (s->now.tm_hour >= 12) { + s->nvram[2] = (to_bcd((now.tm_hour % 12)) + 1) | 0x40; + if (now.tm_hour >= 12) { s->nvram[2] |= 0x20; } } else { - s->nvram[2] = to_bcd(s->now.tm_hour); + s->nvram[2] = to_bcd(now.tm_hour); } - s->nvram[3] = to_bcd(s->now.tm_wday) + 1; - s->nvram[4] = to_bcd(s->now.tm_mday); - s->nvram[5] = to_bcd(s->now.tm_mon) + 1; - s->nvram[6] = to_bcd(s->now.tm_year - 100); + s->nvram[3] = to_bcd(now.tm_wday) + 1; + s->nvram[4] = to_bcd(now.tm_mday); + s->nvram[5] = to_bcd(now.tm_mon) + 1; + s->nvram[6] = to_bcd(now.tm_year - 100); } static void inc_regptr(DS1338State *s) @@ -100,14 +100,15 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) return 0; } if (s->ptr < 8) { - qemu_get_timedate(&s->now, s->offset); + struct tm now; + qemu_get_timedate(&now, s->offset); switch(s->ptr) { case 0: /* TODO: Implement CH (stop) bit. */ - s->now.tm_sec = from_bcd(data & 0x7f); + now.tm_sec = from_bcd(data & 0x7f); break; case 1: - s->now.tm_min = from_bcd(data & 0x7f); + now.tm_min = from_bcd(data & 0x7f); break; case 2: if (data & 0x40) { @@ -119,25 +120,25 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) } else { data = from_bcd(data); } - s->now.tm_hour = data; + now.tm_hour = data; break; case 3: - s->now.tm_wday = from_bcd(data & 7) - 1; + now.tm_wday = from_bcd(data & 7) - 1; break; case 4: - s->now.tm_mday = from_bcd(data & 0x3f); + now.tm_mday = from_bcd(data & 0x3f); break; case 5: - s->now.tm_mon = from_bcd(data & 0x1f) - 1; + now.tm_mon = from_bcd(data & 0x1f) - 1; break; case 6: - s->now.tm_year = from_bcd(data) + 100; + now.tm_year = from_bcd(data) + 100; break; case 7: /* Control register. Currently ignored. */ break; } - s->offset = qemu_timedate_diff(&s->now); + s->offset = qemu_timedate_diff(&now); } else { s->nvram[s->ptr] = data; }