Re: submitting contributions to Zephyr


Nathaniel Graff
 

Hi Nicholas!

I for one am definitely excited about a 64-bit RISC-V port of Zephyr!

You might be interested in this tool from GitHub called ‘hub’: https://hub.github.com/ It provides a command-line interface to GitHub’s web UI.

Nate

On May 21, 2019, at 2:22 PM, Nicolas Pitre <npitre@...> wrote:

Hello,

This is my first post here, however it probably won't be the last.

For a while I've been working on making Zephyr to compile for and run on
64-bit targets. That currently works with the native-posix target,
and 64-bit RISC-V is my next target.

I would like to submit my work for inclusion into the mainline Zephyr
repository. The documented submit and review procedures imply Github
forks and pull requests which involve going through hoops such as a
Javascript-capable web browser and that is not exactly like a walk in
the park for me (my background and credentials are available online if
you want to know why). That would make my life easier if there could
be some alternative way similar to how it is done with the Linux kernel.
Please let me know if that is possible.

I'm therefore posting my first patch here mainly to initiate a
conversation on this issue. Obviously I have many more of them.

----- >8
Subject: [PATCH] fix PTP clock test case

The various ptp_clock_driver_api methods receive a struct ptp_context
not a struct eth_context, and the later must be obtained from a reference
stored in the former. Failing to do so by directly interpreting
driver_data as a struct eth_context instance does end up corrupting
memory past the actual struct ptp_context storage. The test may still
pass as ptp_clock_get() reads from the same out-of-bounds memory as the
previous ptp_clock_set() and therefore the content matches, and with luck
the corrupted memory is not essential to the completion of the test.
But that wasn't my case which allowed me to find this issue.

Fix this by properly obtaining a reference to the struct eth_context
instance via the actual struct ptp_context, and adding one validation
test in my_ptp_clock_set() like the one found in eth_tx() to make sure
we got the right memory.

Signed-off-by: Nicolas Pitre <npitre@...>

diff --git a/tests/net/ptp/clock/src/main.c b/tests/net/ptp/clock/src/main.c
index 1625f6ec18..5d69164694 100644
--- a/tests/net/ptp/clock/src/main.c
+++ b/tests/net/ptp/clock/src/main.c
@@ -175,29 +175,40 @@ static u64_t timestamp_to_nsec(struct net_ptp_time *ts)
return (ts->second * NSEC_PER_SEC) + ts->nanosecond;
}

+struct ptp_context {
+ struct eth_context *eth_context;
+};
+
static int my_ptp_clock_set(struct device *dev, struct net_ptp_time *tm)
{
- struct eth_context *ctx = dev->driver_data;
+ struct ptp_context *ptp_ctx = dev->driver_data;
+ struct eth_context *eth_ctx = ptp_ctx->eth_context;

- memcpy(&ctx->time, tm, sizeof(struct net_ptp_time));
+ if (&eth_context_1 != eth_ctx && &eth_context_2 != eth_ctx) {
+ zassert_true(false, "Context pointers do not match\n");
+ }
+
+ memcpy(&eth_ctx->time, tm, sizeof(struct net_ptp_time));

return 0;
}

static int my_ptp_clock_get(struct device *dev, struct net_ptp_time *tm)
{
- struct eth_context *ctx = dev->driver_data;
+ struct ptp_context *ptp_ctx = dev->driver_data;
+ struct eth_context *eth_ctx = ptp_ctx->eth_context;

- memcpy(tm, &ctx->time, sizeof(struct net_ptp_time));
+ memcpy(tm, &eth_ctx->time, sizeof(struct net_ptp_time));

return 0;
}

static int my_ptp_clock_adjust(struct device *dev, int increment)
{
- struct eth_context *ctx = dev->driver_data;
+ struct ptp_context *ptp_ctx = dev->driver_data;
+ struct eth_context *eth_ctx = ptp_ctx->eth_context;

- ctx->time.nanosecond += increment;
+ eth_ctx->time.nanosecond += increment;

return 0;
}
@@ -207,10 +218,6 @@ static int my_ptp_clock_rate_adjust(struct device *dev, float ratio)
return 0;
}

-struct ptp_context {
- struct eth_context *eth_context;
-};
-
static struct ptp_context ptp_test_1_context;
static struct ptp_context ptp_test_2_context;










Join devel@lists.zephyrproject.org to automatically receive all group messages.