From patchwork Thu Nov 15 19:24:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 10684941 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 4826E13B5 for ; Thu, 15 Nov 2018 19:33:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37F23288BD for ; Thu, 15 Nov 2018 19:33:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3582C2C8FD; Thu, 15 Nov 2018 19:33:45 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CD9992CDE9 for ; Thu, 15 Nov 2018 19:33:44 +0000 (UTC) Received: from localhost ([::1]:40472 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNNOa-0002OV-4B for patchwork-qemu-devel@patchwork.kernel.org; Thu, 15 Nov 2018 14:33:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNNGL-0003YY-M8 for qemu-devel@nongnu.org; Thu, 15 Nov 2018 14:25:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNNGB-00082p-L6 for qemu-devel@nongnu.org; Thu, 15 Nov 2018 14:25:13 -0500 Received: from mail-oi1-x243.google.com ([2607:f8b0:4864:20::243]:34285) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gNNG9-00081b-RQ for qemu-devel@nongnu.org; Thu, 15 Nov 2018 14:25:03 -0500 Received: by mail-oi1-x243.google.com with SMTP id a202-v6so9591528oib.1 for ; Thu, 15 Nov 2018 11:25:00 -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; bh=1ZOBSvKVieP9LJDRldwy3FsgDvauKU5gTBBdjyj+xu4=; b=E3WDitJ3zDTXhnr3Fg6MXpg2qCcALT79BRJVxVGbF/XQh+GWU6g+RKowC2+3rilnrz ablw0fXhM58aqlgLJMYq4RYkNJagOHY79kHvvPEjLoSfR4tXToiFeT+FMmWJ3CrsCsTt NdLmRv2BUu3bIVc6vM7LUdPVvmzKNQw66MLUDqN486mX6AeU88DSi6IT5/1XSibdJDRo 1jupqX1Ngcg5i1tZigwF77GLm/oZjk3fVd/q5Vlb9S3gYFRX4MvFvErWaBu+rRNJj37U Hv6GQ13Ca/uiRGdnZW0AK3kMRqIjiOTiUtfDYrZyjnc1Sf7fvsf/q/3LK8vGdOKGykPg ZRyQ== 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; bh=1ZOBSvKVieP9LJDRldwy3FsgDvauKU5gTBBdjyj+xu4=; b=SEObKHIbjc3shvdSWf5+ZjHEL2jxJBiybaVw9dABXnOR32X4hvZT/e5J1/NFzys3Q+ 14P1Jyt8ZfffHDK7ySdxbGg6qNas8zQJoGVIAxiht0S1+GCea9X5qw+wHW7Bv1dXKuL6 Dqcu84YYfNwu/8VV0u7N5jmuCWTMLd8bt0KEuisoiBMjNOb7MzysENyRO1akosiqjSzV /SM6kLQZfESzqmqW3OOcTG3ILrbv1Q5q39E4T0QAGi2FCSeI40AUb4MAbOgToDDax+2R BpOdof96xAtuJQ9Ue6q3/ZUU/Ya9xkwMKdP3OIdBR256vK87SOjs80jvXx1OpJTOVCO5 KEMA== X-Gm-Message-State: AGRZ1gLnOx+VRyIsnW1Uw/j4xOhxw5x4/TAGfBNanXYPfWRbPehCgowr DDcUOhJUFHO+rSgweRF0SA== X-Google-Smtp-Source: AJdET5eSqF/TveJnm6gbvua8VOYq+OtK1aHNp/IzczSHWEKg80GtICT98phyv5TCN3lx0YPwpxudoQ== X-Received: by 2002:aca:781:: with SMTP id 123-v6mr4487996oih.4.1542309899826; Thu, 15 Nov 2018 11:24:59 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id e195-v6sm11108646oic.26.2018.11.15.11.24.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Nov 2018 11:24:57 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 5F0E51E1C; Thu, 15 Nov 2018 13:24:51 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 03BB830146B; Thu, 15 Nov 2018 13:24:48 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 13:24:43 -0600 Message-Id: <20181115192446.17187-10-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181115192446.17187-1-minyard@acm.org> References: <20181115192446.17187-1-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::243 Subject: [Qemu-devel] [PATCH v2 09/12] i2c: 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: Paolo Bonzini , Corey Minyard , "Dr . David Alan Gilbert" , minyard@acm.org, "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 --- 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 4d25222e23..8d4eed129f 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);