From: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
To: Xen Devel <xen-devel@lists.xensource.com>
Cc: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
Subject: [PATCH 2/3] remove some duplicated code by having helper add/del functions
Date: Tue, 22 Jun 2010 10:26:57 +0100 [thread overview]
Message-ID: <1277198818-27090-3-git-send-email-vincent.hanquez@eu.citrix.com> (raw)
In-Reply-To: <1277198818-27090-1-git-send-email-vincent.hanquez@eu.citrix.com>
[-- Attachment #1: Type: text/plain, Size: 207 bytes --]
Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
---
tools/libxc/xc_flask.c | 227 +++++++++--------------------------------------
1 files changed, 44 insertions(+), 183 deletions(-)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-remove-some-duplicated-code-by-having-helper-add-del.patch --]
[-- Type: text/x-patch; name="0002-remove-some-duplicated-code-by-having-helper-add-del.patch", Size: 7669 bytes --]
diff --git a/tools/libxc/xc_flask.c b/tools/libxc/xc_flask.c
index 3b733e5..12cb001 100644
--- a/tools/libxc/xc_flask.c
+++ b/tools/libxc/xc_flask.c
@@ -141,237 +141,98 @@ int xc_flask_setenforce(xc_interface *xc_handle, int mode)
return 0;
}
-int xc_flask_add_pirq(xc_interface *xc_handle, unsigned int pirq, char *scontext)
+static int xc_flask_add(xc_interface *xc_handle, char *cat, char *arg, char *scontext)
{
- int err;
+ char buf[512];
flask_op_t op;
- char *buf;
- char *pirq_s = OCON_PIRQ_STR;
- int size = INITCONTEXTLEN + strlen(pirq_s) + (sizeof(unsigned int)) +
- (sizeof(char) * 3);
-
- if ( (buf = (char *) malloc(size)) == NULL )
- return -ENOMEM;
- memset(buf, 0, size);
+ memset(buf, 0, 512);
+ snprintf(buf, 512, "%s %255s %s", cat, scontext, arg);
op.cmd = FLASK_ADD_OCONTEXT;
- snprintf(buf, size, "%s %255s %u", pirq_s, scontext, pirq);
op.buf = buf;
- op.size = size;
-
- if ( (err = xc_flask_op(xc_handle, &op)) != 0 )
- {
- free(buf);
- return err;
- }
+ op.size = 512;
+
+ return xc_flask_op(xc_handle, &op);
+}
- free(buf);
- return 0;
+int xc_flask_add_pirq(xc_interface *xc_handle, unsigned int pirq, char *scontext)
+{
+ char arg[16];
+ snprintf(arg, 16, "%u", pirq);
+ return xc_flask_add(xc_handle, OCON_PIRQ_STR, arg, scontext);
}
int xc_flask_add_ioport(xc_interface *xc_handle, unsigned long low, unsigned long high,
char *scontext)
{
- int err;
- flask_op_t op;
- char *buf;
- char *ioport = OCON_IOPORT_STR;
- int size = INITCONTEXTLEN + strlen(ioport) +
- (sizeof(unsigned long) * 2) + (sizeof(char) * 4);
-
- if ( (buf = (char *) malloc(size)) == NULL )
- return -ENOMEM;
- memset(buf, 0, size);
-
- op.cmd = FLASK_ADD_OCONTEXT;
- snprintf(buf, size, "%s %255s %lu %lu", ioport, scontext, low, high);
- op.buf = buf;
- op.size = size;
-
- if ( (err = xc_flask_op(xc_handle, &op)) != 0 )
- {
- free(buf);
- return err;
- }
-
- free(buf);
- return 0;
+ char arg[64];
+ snprintf(arg, 64, "%lu %lu", low, high);
+ return xc_flask_add(xc_handle, OCON_IOPORT_STR, arg, scontext);
}
int xc_flask_add_iomem(xc_interface *xc_handle, unsigned long low, unsigned long high,
char *scontext)
{
- int err;
- flask_op_t op;
- char *buf;
- char *iomem = OCON_IOMEM_STR;
- int size = INITCONTEXTLEN + strlen(iomem) +
- (sizeof(unsigned long) * 2) + (sizeof(char) * 4);
-
- if ( (buf = (char *) malloc(size)) == NULL )
- return -ENOMEM;
- memset(buf, 0, size);
-
- op.cmd = FLASK_ADD_OCONTEXT;
- snprintf(buf, size, "%s %255s %lu %lu", iomem, scontext, low, high);
- op.buf = buf;
- op.size = size;
-
- if ( (err = xc_flask_op(xc_handle, &op)) != 0 )
- {
- free(buf);
- return err;
- }
-
- free(buf);
- return 0;
+ char arg[64];
+ snprintf(arg, 64, "%lu %lu", low, high);
+ return xc_flask_add(xc_handle, OCON_IOMEM_STR, arg, scontext);
}
int xc_flask_add_device(xc_interface *xc_handle, unsigned long device, char *scontext)
{
- int err;
- flask_op_t op;
- char *buf;
- char *dev = OCON_DEVICE_STR;
- int size = INITCONTEXTLEN + strlen(dev) + (sizeof(unsigned long)) +
- (sizeof(char) * 3);
-
- if ( (buf = (char *) malloc(size)) == NULL )
- return -ENOMEM;
- memset(buf, 0, size);
-
- op.cmd = FLASK_ADD_OCONTEXT;
- snprintf(buf, size, "%s %255s %lu", dev, scontext, device);
- op.buf = buf;
- op.size = size;
-
- if ( (err = xc_flask_op(xc_handle, &op)) != 0 )
- {
- free(buf);
- return err;
- }
-
- free(buf);
- return 0;
+ char arg[32];
+ snprintf(arg, 32, "%lu", device);
+ return xc_flask_add(xc_handle, OCON_DEVICE_STR, arg, scontext);
}
-int xc_flask_del_pirq(xc_interface *xc_handle, unsigned int pirq)
+static int xc_flask_del(xc_interface *xc_handle, char *cat, char *arg)
{
- int err;
+ char buf[256];
flask_op_t op;
- char *buf;
- char *pirq_s = OCON_PIRQ_STR;
- int size = strlen(pirq_s) + (sizeof(unsigned int)) +
- (sizeof(char) * 2);
-
- if ( (buf = (char *) malloc(size)) == NULL )
- return -ENOMEM;
- memset(buf, 0, size);
+ memset(buf, 0, 256);
+ snprintf(buf, 256, "%s %s", cat, arg);
op.cmd = FLASK_DEL_OCONTEXT;
- snprintf(buf, size, "%s %u", pirq_s, pirq);
op.buf = buf;
- op.size = size;
-
- if ( (err = xc_flask_op(xc_handle, &op)) != 0 )
- {
- free(buf);
- return err;
- }
+ op.size = 256;
+
+ return xc_flask_op(xc_handle, &op);
+}
- free(buf);
- return 0;
+int xc_flask_del_pirq(xc_interface *xc_handle, unsigned int pirq)
+{
+ char arg[16];
+ snprintf(arg, 16, "%u", pirq);
+ return xc_flask_del(xc_handle, OCON_PIRQ_STR, arg);
}
int xc_flask_del_ioport(xc_interface *xc_handle, unsigned long low, unsigned long high)
{
- int err;
- flask_op_t op;
- char *buf;
- char *ioport = OCON_IOPORT_STR;
- int size = strlen(ioport) + (sizeof(unsigned long) * 2) +
- (sizeof(char) * 3);
-
- if ( (buf = (char *) malloc(size)) == NULL )
- return -ENOMEM;
- memset(buf, 0, size);
-
- op.cmd = FLASK_DEL_OCONTEXT;
- snprintf(buf, size, "%s %lu %lu", ioport, low, high);
- op.buf = buf;
- op.size = size;
-
- if ( (err = xc_flask_op(xc_handle, &op)) != 0 )
- {
- free(buf);
- return err;
- }
-
- free(buf);
- return 0;
+ char arg[64];
+ snprintf(arg, 64, "%lu %lu", low, high);
+ return xc_flask_del(xc_handle, OCON_IOPORT_STR, arg);
}
int xc_flask_del_iomem(xc_interface *xc_handle, unsigned long low, unsigned long high)
{
- int err;
- flask_op_t op;
- char *buf;
- char *iomem = OCON_IOMEM_STR;
- int size = strlen(iomem) + (sizeof(unsigned long) * 2) +
- (sizeof(char) * 3);
-
- if ( (buf = (char *) malloc(size)) == NULL )
- return -ENOMEM;
- memset(buf, 0, size);
-
- op.cmd = FLASK_DEL_OCONTEXT;
- snprintf(buf, size, "%s %lu %lu", iomem, low, high);
- op.buf = buf;
- op.size = size;
-
- if ( (err = xc_flask_op(xc_handle, &op)) != 0 )
- {
- free(buf);
- return err;
- }
-
- free(buf);
- return 0;
+ char arg[64];
+ snprintf(arg, 64, "%lu %lu", low, high);
+ return xc_flask_del(xc_handle, OCON_IOMEM_STR, arg);
}
int xc_flask_del_device(xc_interface *xc_handle, unsigned long device)
{
- int err;
- flask_op_t op;
- char *buf;
- char *dev = OCON_DEVICE_STR;
- int size = strlen(dev) + (sizeof(unsigned long)) + (sizeof(char) * 2);
-
- if ( (buf = (char *) malloc(size)) == NULL )
- return -ENOMEM;
- memset(buf, 0, size);
-
- op.cmd = FLASK_DEL_OCONTEXT;
- snprintf(buf, size, "%s %lu", dev, device);
- op.buf = buf;
- op.size = size;
-
- if ( (err = xc_flask_op(xc_handle, &op)) != 0 )
- {
- free(buf);
- return err;
- }
-
- free(buf);
- return 0;
+ char arg[32];
+ snprintf(arg, 32, "%lu", device);
+ return xc_flask_del(xc_handle, OCON_DEVICE_STR, arg);
}
int xc_flask_access(xc_interface *xc_handle, const char *scon, const char *tcon,
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
next prev parent reply other threads:[~2010-06-22 9:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-22 9:26 [PATCH 0/3] libflask merging in libxenctrl Vincent Hanquez
2010-06-22 9:26 ` [PATCH 1/3] merge libflask into libxenctrl Vincent Hanquez
2010-06-22 9:26 ` Vincent Hanquez [this message]
2010-06-22 9:26 ` [PATCH 3/3] add flask capabilities in python xc bindings Vincent Hanquez
2010-06-22 9:50 ` [PATCH 0/3] libflask merging in libxenctrl Tim Deegan
2010-06-22 10:04 ` Tim Deegan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1277198818-27090-3-git-send-email-vincent.hanquez@eu.citrix.com \
--to=vincent.hanquez@eu.citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).