From patchwork Mon Jan 28 17:54:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 10784289 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D68DB1390 for ; Mon, 28 Jan 2019 18:12:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C6DCB2BFCD for ; Mon, 28 Jan 2019 18:12:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BAC3F2BFCE; Mon, 28 Jan 2019 18:12:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3E6B52BFD1 for ; Mon, 28 Jan 2019 18:11:59 +0000 (UTC) Received: from localhost ([127.0.0.1]:36360 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBO2-0003Xv-Gr for patchwork-qemu-devel@patchwork.kernel.org; Mon, 28 Jan 2019 13:11:58 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37045) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBED-0003Db-HM for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB8V-0005ta-06 for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:56:03 -0500 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:34205) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB8U-0005cJ-PN for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:54 -0500 Received: by mail-pf1-x442.google.com with SMTP id h3so8353036pfg.1 for ; Mon, 28 Jan 2019 09:55:23 -0800 (PST) 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=XH0JtuomOh1872pyaHH51ab2ohSNk7NtbAOrPXjiPwE=; b=ronz2TwGoiGqFeF/fTokk5g7TxeFIUOjQSlrW+u8zGZW91PGBQARMDiCtBp5pBBk9W qkUqOf/YJKU8lIAjuJB7usZbnkAC86FiZoMNYOtwTnJq7Vjo0WbJGhqobn+1mOE0vcUD PY43h6WwlMHGowtBvagi8rB4KrgFm1swzgWbEqmiIWGs5QHlLMJmEiQWZD2TcouD65bt tPXMx7lNW6oInay/Te5rNdefTG8pNQkEOg/OdkoFBBopUpSdx8g5t8a5t5KgI0iLPrhe 515ipCsuE0qe3ry3qjh0kdMx5vrFevmRw5SUTFVEWj+7RUx/Yz0IccBY8+IyhdyXthSU pYtA== 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=XH0JtuomOh1872pyaHH51ab2ohSNk7NtbAOrPXjiPwE=; b=XAHTugXXP6iSPsr6WHK1bRa8Lsj4p8gMngQ6J9m6k1LM01mAXu5j8Pyx7oBwMFFFYf 8QWN3bWnnsy7p11zw/rP6/TNJlk1USS+n5QU5ZGK0e1pfIsdyo8ztO6j5pZt+mojLrDA uWzHml2hm3hBk1h4i4tCP5KzhQbr0gtNDHTt1YABbHQi/Rrrmv7N95s7bs7FKaFa373a HgHK2Fhl3XCvJI1I9nDtzthmUbHjurFEEaHz+bqE7g2pWQOSafZmubtlQZLEJh8wFBh4 aOnTb6+QgKB+yACeHVXiCJjafLzMM01SyRBC3J+6R/NWWJouXvB1u00acgziGELvPk7i ymAg== X-Gm-Message-State: AJcUukfRJZj2tF7/2Kpsk+uA+oyTTDl1RDZwHczfRgKt2Wjjqx2CEYiO Nno8WxJ0SOFTAKVhR8qBLg== X-Google-Smtp-Source: ALg8bN5eH4Tkl9W0zA6RcXzAAZVQel5vnvS/8dMFR1X46xIM8GiwMASLL536/xugzWW69DO/jxpqAg== X-Received: by 2002:a63:61c8:: with SMTP id v191mr20881248pgb.242.1548698122152; Mon, 28 Jan 2019 09:55:22 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id l70sm62441308pgd.20.2019.01.28.09.55.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 09:55:16 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:c8f8:7971:e432:a838]) by serve.minyard.net (Postfix) with ESMTPA id 68F9C106D; Mon, 28 Jan 2019 11:55:13 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 86AF1301162; Mon, 28 Jan 2019 11:55:10 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:54 -0600 Message-Id: <20190128175458.27255-16-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128175458.27255-1-minyard@acm.org> References: <20190128175458.27255-1-minyard@acm.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH v4 15/19] i2c:smbus_eeprom: Add normal type name and cast to smbus_eeprom.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Corey Minyard Create a type name and a cast macro and use those through the code. Signed-off-by: Corey Minyard Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé --- hw/i2c/smbus_eeprom.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/hw/i2c/smbus_eeprom.c b/hw/i2c/smbus_eeprom.c index 62e634c745..91d68ff588 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -30,6 +30,11 @@ //#define DEBUG +#define TYPE_SMBUS_EEPROM "smbus-eeprom" + +#define SMBUS_EEPROM(obj) \ + OBJECT_CHECK(SMBusEEPROMDevice, (obj), TYPE_SMBUS_EEPROM) + typedef struct SMBusEEPROMDevice { SMBusDevice smbusdev; void *data; @@ -38,7 +43,7 @@ typedef struct SMBusEEPROMDevice { static uint8_t eeprom_receive_byte(SMBusDevice *dev) { - SMBusEEPROMDevice *eeprom = (SMBusEEPROMDevice *) dev; + SMBusEEPROMDevice *eeprom = SMBUS_EEPROM(dev); uint8_t *data = eeprom->data; uint8_t val = data[eeprom->offset++]; @@ -51,7 +56,7 @@ static uint8_t eeprom_receive_byte(SMBusDevice *dev) static int eeprom_write_data(SMBusDevice *dev, uint8_t *buf, uint8_t len) { - SMBusEEPROMDevice *eeprom = (SMBusEEPROMDevice *) dev; + SMBusEEPROMDevice *eeprom = SMBUS_EEPROM(dev); uint8_t *data = eeprom->data; #ifdef DEBUG @@ -73,7 +78,7 @@ static int eeprom_write_data(SMBusDevice *dev, uint8_t *buf, uint8_t len) static void smbus_eeprom_realize(DeviceState *dev, Error **errp) { - SMBusEEPROMDevice *eeprom = (SMBusEEPROMDevice *)dev; + SMBusEEPROMDevice *eeprom = SMBUS_EEPROM(dev); eeprom->offset = 0; } @@ -97,7 +102,7 @@ static void smbus_eeprom_class_initfn(ObjectClass *klass, void *data) } static const TypeInfo smbus_eeprom_info = { - .name = "smbus-eeprom", + .name = TYPE_SMBUS_EEPROM, .parent = TYPE_SMBUS_DEVICE, .instance_size = sizeof(SMBusEEPROMDevice), .class_init = smbus_eeprom_class_initfn, @@ -114,7 +119,7 @@ void smbus_eeprom_init_one(I2CBus *smbus, uint8_t address, uint8_t *eeprom_buf) { DeviceState *dev; - dev = qdev_create((BusState *) smbus, "smbus-eeprom"); + dev = qdev_create((BusState *) smbus, TYPE_SMBUS_EEPROM); qdev_prop_set_uint8(dev, "address", address); qdev_prop_set_ptr(dev, "data", eeprom_buf); qdev_init_nofail(dev);