From patchwork Mon Nov 26 20:04:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 10699143 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 596A616B1 for ; Mon, 26 Nov 2018 20:33:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46FE629784 for ; Mon, 26 Nov 2018 20:33:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37BE329905; Mon, 26 Nov 2018 20:33:48 +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 30CDF29784 for ; Mon, 26 Nov 2018 20:33:46 +0000 (UTC) Received: from localhost ([::1]:38725 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gRNZh-0002ST-Da for patchwork-qemu-devel@patchwork.kernel.org; Mon, 26 Nov 2018 15:33:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53704) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gRN81-0001lD-C1 for qemu-devel@nongnu.org; Mon, 26 Nov 2018 15:05:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gRN7y-0001Lb-S7 for qemu-devel@nongnu.org; Mon, 26 Nov 2018 15:05:09 -0500 Received: from mail-oi1-x243.google.com ([2607:f8b0:4864:20::243]:43919) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gRN7y-0001JL-HI for qemu-devel@nongnu.org; Mon, 26 Nov 2018 15:05:06 -0500 Received: by mail-oi1-x243.google.com with SMTP id u18so17068056oie.10 for ; Mon, 26 Nov 2018 12:05:02 -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=a9SFFzWbVmV4wiFtLAG/ZGimMa+HdsxX+nv8R2lrHko=; b=GbU9Kx8G6AtRNYcapF5weyXXfJ9LFJP34gJY0XwyFizA0AfWWQD80hGrDmHdbLFiez f4jLHaRhlE2iTJy8lHYfO3mAMDcl3CNXx66Lv4z1eVpBF7M1nH0UjQCWow8fPvPJ21kV vkckoPZllbzdIqtc+ENiBVQ1CPytzrJITwjfY/Zmv+0U19byKOPSMjX0aeBVJ5drUa8l TDSq/LRB8Aiw50uH9UvsZ9Q1gd7ZBCKZX5btxFpGE5umBs32AGqMfOTnmBjZ8cPPlcLT G1WNi7ZBLTMq/juvQeLvePqyBwsYAZcZZ/YQk6WLWdlZwD0sdGbQnFUT2LU6mLsh57ci vKRg== 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=a9SFFzWbVmV4wiFtLAG/ZGimMa+HdsxX+nv8R2lrHko=; b=DdyZkNqgNGmE9or8WMAAkm6vr8J7HOj6hSxxV9blmHbEDwE2lhFBiNOTZhu904Jz0Y ek6RqvOv6FdmLa7pgNPo7lraYfTHhlq75Ic8QjWg3jv+v7WRrLYok0uctACmaDzsnZ5E LpI8ajBQP4MGKM5GkAVodVrxnDIUawf3FZZZeWh7slt7S4cmssOf9Bi3g1NUYIMEivGV xy4YwjywPy+6bQDsY8t+zGdQpf7tfwTZK5uJzCWjFKdg7kyK3Cm1XVd1D5glpiT2U+LY Ka5aVwHfT3hZcg5ei7UHJ2lBuOGolmG+5GD1EXpbT/yx0CJv9IA6O2cuJ/NXkKK5u8S9 Bm6A== X-Gm-Message-State: AGRZ1gKCkjn48tQ4v43VUPD4BcGiKs7lSQ1w+7V8rDoIpPVLvhahOPye 2cScmsoJI2nQr7LWWHzBSLFIy0w= X-Google-Smtp-Source: AJdET5fV65LFc2Y9kdMODH0xrTRlx66NQokCpQvMV5fHBSzJHekIitFHWNakGZZYYxUNr4WUVi21AQ== X-Received: by 2002:aca:cf04:: with SMTP id f4mr16890649oig.16.1543262701925; Mon, 26 Nov 2018 12:05:01 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id n185sm459115oih.18.2018.11.26.12.04.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Nov 2018 12:04:58 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id C362A1E62; Mon, 26 Nov 2018 14:04:49 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id BD83A30146D; Mon, 26 Nov 2018 14:04:46 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Peter Maydell Date: Mon, 26 Nov 2018 14:04:31 -0600 Message-Id: <20181126200435.23408-13-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181126200435.23408-1-minyard@acm.org> References: <20181126200435.23408-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 v3 12/16] 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: 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 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);