From patchwork Thu Feb 28 18:17:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 10833569 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 BD5AE1515 for ; Thu, 28 Feb 2019 18:23:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A54AF2F5B7 for ; Thu, 28 Feb 2019 18:23:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 976C72F5F1; Thu, 28 Feb 2019 18:23:11 +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 3AB342F5B7 for ; Thu, 28 Feb 2019 18:23:11 +0000 (UTC) Received: from localhost ([127.0.0.1]:44555 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQKs-0003Ld-GX for patchwork-qemu-devel@patchwork.kernel.org; Thu, 28 Feb 2019 13:23:10 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46626) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQFe-0000VK-BM for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzQFV-0002I8-N8 for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:42 -0500 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]:46741) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzQFV-0002DP-E3 for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:37 -0500 Received: by mail-ot1-x341.google.com with SMTP id c18so18489701otl.13 for ; Thu, 28 Feb 2019 10:17:29 -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=phVcIZ91pPZo7YJfCc5Psb+Hz4cvw3ogTugWINPoDh8=; b=I7CSSJF+P2yXXOO2uudtf+4mzFOXaprMGtUInhKW96IZkCxtO+5qRXvjtFDnbzAKmd bY7HD1z8rnRuZ/m630jCgbhvpjRpxleLD/++Il9BE2QdtiR07oEKtn9vRODUWo5Ha87l lWxu8dejdqMdpT6e1Veut8IJ2lDCsZwm8HaQvq/2K7kr1LdoYoTrtXIb5W2HrOQbg258 5CNTyHwPp+3liV15+qd0z5MFJ/aJnMPbmliT9ec7koU1hG4fq+dj4CGUdKuwqr6Obqun ZhPK/LUm+hcI62myLKmqd4JqJ8rid8GrGhLNZofFqxLkyrAw1HK8kT3IF9pQQr+5iOfp MFMA== 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=phVcIZ91pPZo7YJfCc5Psb+Hz4cvw3ogTugWINPoDh8=; b=joi7hwxqKX5OsthBry3+70E27S12D82TZeB18YdS6WyvYOhhPWRVYrlK8ZyhFYxjKI hFVm4L2rDN5ucZQ8BdtYFlA7Yv78apm/T2rqHrhmi4C2w5avGPuzM68XeYz1pxx1ifcc SQlKwFcKrzVjzGZEZTn+hWC7hZVEMYtT2nbTcyFpngrhc4Z0XJ3+9CnxzFf61icjsy/u xtrPOANpxcj9qurMaqDnDsgIMP1k6fne6raFHMtcsY0NQ9L/bXSSITNbtwYL1vEexlXV nnfSmKh27/ozxGKlIXfiRk+mpozTccArXfyTVALULeIzH5AANLdIHPTJzXgQbWSE6YA4 Ovhw== X-Gm-Message-State: APjAAAXWaF0MqUXrdWBjzDiY0rSaYslkYQ3L9UaMJuwdzP0a2lR0IluF ZFslV0mlFiJzXbMCNhliSg== X-Google-Smtp-Source: APXvYqy0V2RjpSQqryNbXI5/23Z+sDNJGBqNOcq8QRu2YYwFByHwfoHMcW0CuNvXAioVRz6Es+ei+w== X-Received: by 2002:a9d:2944:: with SMTP id d62mr642525otb.193.1551377848407; Thu, 28 Feb 2019 10:17:28 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id 3sm5363623ots.75.2019.02.28.10.17.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Feb 2019 10:17:25 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id ACD9A1808FF; Thu, 28 Feb 2019 18:17:14 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 721B63028CF; Thu, 28 Feb 2019 12:17:14 -0600 (CST) From: minyard@acm.org To: Peter Maydell Date: Thu, 28 Feb 2019 12:17:06 -0600 Message-Id: <20190228181710.2477-16-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190228181710.2477-1-minyard@acm.org> References: <20190228181710.2477-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::341 Subject: [Qemu-devel] [PULL 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: Corey Minyard , QEMU Developers , minyard@acm.org 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 2816e35bcc..76f0d4aab0 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -32,6 +32,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; @@ -40,7 +45,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++]; @@ -53,7 +58,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 @@ -75,7 +80,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; } @@ -99,7 +104,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, @@ -116,7 +121,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);