Skip to content

Commit

Permalink
Merge pull request #3 from otya128/develop
Browse files Browse the repository at this point in the history
otya128氏のメモリ処理変更を取り込んでみる
  • Loading branch information
techmadot authored Sep 2, 2023
2 parents ea3adf3 + 1c1e6fa commit 79bb2fe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
27 changes: 18 additions & 9 deletions driver/itedtv_bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,19 @@ static int itedtv_usb_alloc_urb_buffers(struct itedtv_usb_context *ctx,

if (!urb->transfer_buffer) {
#ifdef __linux__
#ifdef __GFP_RETRY_MAYFAIL
if (!no_dma)
p = usb_alloc_coherent(dev, buf_size,
GFP_KERNEL, &dma);
GFP_KERNEL | __GFP_RETRY_MAYFAIL, &dma);
else
p = kmalloc(buf_size, GFP_KERNEL);
p = kmalloc(buf_size, GFP_KERNEL | __GFP_RETRY_MAYFAIL);
#else
if (!no_dma)
p = usb_alloc_coherent(dev, buf_size,
GFP_KERNEL | __GFP_REPEAT, &dma);
else
p = kmalloc(buf_size, GFP_KERNEL | __GFP_REPEAT);
#endif
#else
p = kmalloc(buf_size, GFP_KERNEL);
#endif
Expand Down Expand Up @@ -363,27 +371,27 @@ static void itedtv_usb_free_urb_buffers(struct itedtv_usb_context *ctx,
return;
}

static void itedtv_usb_clean_context(struct itedtv_usb_context *ctx)
static void itedtv_usb_clean_context(struct itedtv_usb_context *ctx, bool free_works)
{
#ifdef ITEDTV_BUS_USE_WORKQUEUE
if (ctx->wq)
destroy_workqueue(ctx->wq);
#endif

if (ctx->works) {
if (free_works && ctx->works) {
itedtv_usb_free_urb_buffers(ctx, true);
kfree(ctx->works);
ctx->num_urb = 0;
ctx->works = NULL;
ctx->num_works = 0;
}

ctx->stream_handler = NULL;
ctx->ctx = NULL;
ctx->num_urb = 0;
ctx->no_dma = false;
#ifdef ITEDTV_BUS_USE_WORKQUEUE
ctx->wq = NULL;
#endif
ctx->num_works = 0;
ctx->works = NULL;

return;
}
Expand Down Expand Up @@ -481,7 +489,7 @@ static int itedtv_usb_start_streaming(struct itedtv_bus *bus,
flush_workqueue(ctx->wq);
#endif

itedtv_usb_clean_context(ctx);
itedtv_usb_clean_context(ctx, true);

mutex_unlock(&ctx->lock);

Expand Down Expand Up @@ -512,7 +520,7 @@ static int itedtv_usb_stop_streaming(struct itedtv_bus *bus)
usb_kill_urb(works[i].urb);
}

itedtv_usb_clean_context(ctx);
itedtv_usb_clean_context(ctx, false);

mutex_unlock(&ctx->lock);

Expand Down Expand Up @@ -603,6 +611,7 @@ int itedtv_bus_term(struct itedtv_bus *bus)
if (atomic_read_acquire(&ctx->streaming))
itedtv_usb_stop_streaming(bus);

itedtv_usb_clean_context(ctx, true);
mutex_destroy(&ctx->lock);
kfree(ctx);
}
Expand Down
4 changes: 2 additions & 2 deletions driver/ptx_chrdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static long ptx_chrdev_unlocked_ioctl(struct file *file,
break;
} else if (freq.freq_no < 12) {
/* BS */
if (freq.slot >= 8) {
if (0 && freq.slot >= 8) {
ret = -EINVAL;
break;
}
Expand Down Expand Up @@ -268,7 +268,7 @@ static long ptx_chrdev_unlocked_ioctl(struct file *file,
break;
} else if (freq.freq_no < 12) {
/* BS */
if (freq.slot >= 8) {
if (0 && freq.slot >= 8) {
ret = -EINVAL;
break;
}
Expand Down
7 changes: 6 additions & 1 deletion driver/ringbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,13 @@ int ringbuffer_alloc(struct ringbuffer *ringbuf, size_t size)
ringbuffer_reset_nolock(ringbuf);

if (!ringbuf->buf) {
ringbuf->buf = (u8 *)__get_free_pages(GFP_KERNEL,
#ifdef __GFP_RETRY_MAYFAIL
ringbuf->buf = (u8 *)__get_free_pages(GFP_KERNEL | __GFP_RETRY_MAYFAIL,
get_order(size));
#else
ringbuf->buf = (u8 *)__get_free_pages(GFP_KERNEL | __GFP_REPEAT,
get_order(size));
#endif
if (!ringbuf->buf)
ret = -ENOMEM;
else
Expand Down

0 comments on commit 79bb2fe

Please sign in to comment.