mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Aditya Garg <gargaditya08@live.com>
To: Thomas Zimmermann <tzimmermann@suse.de>
Cc: "maarten.lankhorst@linux.intel.com"
	<maarten.lankhorst@linux.intel.com>,
	"mripard@kernel.org" <mripard@kernel.org>,
	"airlied@gmail.com" <airlied@gmail.com>,
	"simona@ffwll.ch" <simona@ffwll.ch>,
	Kerem Karabay <kekrby@gmail.com>,
	Atharva Tiwari <evepolonium@gmail.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH 2/2] drm/tiny: add driver for Apple Touch Bars in x86 Macs
Date: Wed, 19 Feb 2025 09:37:34 +0000	[thread overview]
Message-ID: <858CA9AF-6128-4974-9C98-9EC01FF4FDB1@live.com> (raw)
In-Reply-To: <a88a6e48-8c55-410b-b553-8942dac3608a@suse.de>

Hi

>> I’ve tried these changes, seem to be breaking the driver:
>> 
>> —>8—
>> From 16c920cabf65ec664663ebe1611c0ccf6e81de4a Mon Sep 17 00:00:00 2001
>> From: Aditya Garg <gargaditya08@live.com>
>> Date: Tue, 18 Feb 2025 18:54:10 +0530
>> Subject: [PATCH] better error handling
>> 
>> ---
>>  .../apple-touchbar-advanced-0.1/appletbdrm.c  | 68 +++++++++++++------
>>  1 file changed, 46 insertions(+), 22 deletions(-)
>> 
>> diff --git a/usr/src/apple-touchbar-advanced-0.1/appletbdrm.c b/usr/src/apple-touchbar-advanced-0.1/appletbdrm.c
>> index f2d9113..cb13b36 100644
>> --- a/usr/src/apple-touchbar-advanced-0.1/appletbdrm.c
>> +++ b/usr/src/apple-touchbar-advanced-0.1/appletbdrm.c
>> @@ -133,6 +133,17 @@ struct appletbdrm_device {
>>   struct drm_encoder encoder;
>>  };
>>  +struct appletbdrm_plane_state {
>> + struct drm_shadow_plane_state base;
>> + u8 *request_buffer;
>> + u8 *response_buffer;
>> +};
>> +
>> +static inline struct appletbdrm_plane_state *to_appletbdrm_plane_state(struct drm_plane_state *state)
>> +{
>> + return container_of(state, struct appletbdrm_plane_state, base.base);
>> +}
>> +
>>  static int appletbdrm_send_request(struct appletbdrm_device *adev,
>>     struct appletbdrm_msg_request_header *request, size_t size)
>>  {
>> @@ -311,24 +322,6 @@ static int appletbdrm_flush_damage(struct appletbdrm_device *adev,
>>   if (!frames_size)
>>   return 0;
>>  - request_size = ALIGN(sizeof(*request) + frames_size + sizeof(*footer), 16);
>> -
>> - request = kzalloc(request_size, GFP_KERNEL);
>> - if (!request)
>> - return -ENOMEM;
>> -
>> - response = kzalloc(sizeof(*response), GFP_KERNEL);
>> - if (!response) {
>> - ret = -ENOMEM;
>> - goto free_request;
>> - }
>> -
>> - ret = drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE);
>> - if (ret) {
>> - drm_err(drm, "Failed to start CPU framebuffer access (%d)\n", ret);
>> - goto free_response;
>> - }
>> -
>>   request->header.unk_00 = cpu_to_le16(2);
>>   request->header.unk_02 = cpu_to_le16(0x12);
>>   request->header.unk_04 = cpu_to_le32(9);
>> @@ -389,10 +382,6 @@ static int appletbdrm_flush_damage(struct appletbdrm_device *adev,
>>    end_fb_cpu_access:
>>   drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE);
>> -free_response:
>> - kfree(response);
>> -free_request:
>> - kfree(request);
>>     return ret;
>>  }
>> @@ -415,6 +404,15 @@ static int appletbdrm_primary_plane_helper_atomic_check(struct drm_plane *plane,
>>   struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state, plane);
>>   struct drm_crtc *new_crtc = new_plane_state->crtc;
>>   struct drm_crtc_state *new_crtc_state = NULL;
>> + struct appletbdrm_plane_state *appletbdrm_state = to_appletbdrm_plane_state(new_plane_state);
>> + struct drm_device *drm = plane->dev;
>> + struct drm_plane_state *plane_state = plane->state;
>> + struct appletbdrm_fb_request_response *response;
>> + struct appletbdrm_fb_request_footer *footer;
>> + struct drm_framebuffer *fb = plane_state->fb;
>> + struct appletbdrm_fb_request *request;
>> + size_t frames_size = 0;
>> + size_t request_size;
>>   int ret;
>>     if (new_crtc)
>> @@ -429,6 +427,22 @@ static int appletbdrm_primary_plane_helper_atomic_check(struct drm_plane *plane,
>>   else if (!new_plane_state->visible)
>>   return 0;
>>  + request_size = ALIGN(sizeof(*request) + frames_size + sizeof(*footer), 16);
>> +
>> + appletbdrm_state->request_buffer = kzalloc(request_size, GFP_KERNEL);
>> + if (!request)
>> + return -ENOMEM;
>> +
>> + appletbdrm_state->response_buffer = kzalloc(sizeof(*response), GFP_KERNEL);
>> + if (!response) {
>> + ret = -ENOMEM;
>> + }
>> +
>> + ret = drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE);
>> + if (ret) {
>> + drm_err(drm, "Failed to start CPU framebuffer access (%d)\n", ret);
>> + }
>> +
>>   return 0;
>>  }
>>  @@ -464,6 +478,15 @@ static void appletbdrm_primary_plane_helper_atomic_disable(struct drm_plane *pla
>>   drm_dev_exit(idx);
>>  }
>>  +static void appletbdrm_primary_plane_destroy_state(struct drm_plane *plane,
>> + struct drm_plane_state *state)
>> +{
>> + struct appletbdrm_plane_state *appletbdrm_state = to_appletbdrm_plane_state(state);
>> +
>> + kfree(appletbdrm_state->request_buffer);
>> + kfree(appletbdrm_state->response_buffer);
>> +}
>> +
>>  static const struct drm_plane_helper_funcs appletbdrm_primary_plane_helper_funcs = {
>>   DRM_GEM_SHADOW_PLANE_HELPER_FUNCS,
>>   .atomic_check = appletbdrm_primary_plane_helper_atomic_check,
>> @@ -474,6 +497,7 @@ static const struct drm_plane_helper_funcs appletbdrm_primary_plane_helper_funcs
>>  static const struct drm_plane_funcs appletbdrm_primary_plane_funcs = {
>>   .update_plane = drm_atomic_helper_update_plane,
>>   .disable_plane = drm_atomic_helper_disable_plane,
>> + .atomic_destroy_state = appletbdrm_primary_plane_destroy_state,
>>   .destroy = drm_plane_cleanup,
>>   DRM_GEM_SHADOW_PLANE_FUNCS,
> 
> You don't allocate struct appletbdrm_plane_state. Instead of this macro, you also have to set your own helpers for the plane's .reset and .atomic_duplicate_state There's again example code in the ssd130x driver.

Any attempt make to allocate request and response outside appletdrm_flush_damage seems to be breaking the driver.

If I understand correctly, you want me to allocate them outside appletdrm_flush_damage, in appletbdrm_primary_plane_helper_atomic_check, return -ENOMEM if they fail. After that add kfree(return) and kfree(response) in appletbdrm_primary_plane_destroy_state.

The ssd130x driver example isn’t really helping me. Could you please help me out here?

  reply	other threads:[~2025-02-19  9:37 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-17 18:51 [PATCH 1/2] drm/format-helper: add helper for BGR888 to XRGB8888 conversion Aditya Garg
2025-02-17 18:52 ` [PATCH 2/2] drm/tiny: add driver for Apple Touch Bars in x86 Macs Aditya Garg
2025-02-18 10:09   ` Thomas Zimmermann
2025-02-18 13:49     ` Aditya Garg
2025-02-19  7:52       ` Thomas Zimmermann
2025-02-19  9:37         ` Aditya Garg [this message]
2025-02-19  9:49           ` Thomas Zimmermann
2025-02-19 10:19             ` Aditya Garg
2025-02-20 10:20               ` Thomas Zimmermann
2025-02-20 11:00                 ` Aditya Garg
2025-02-20 16:44                   ` Aditya Garg
2025-02-18 20:12     ` Aditya Garg
2025-02-19  7:57       ` Thomas Zimmermann
2025-02-19  8:02         ` Thomas Zimmermann
2025-02-20 17:23         ` Aditya Garg
2025-02-20 10:11     ` Aditya Garg
2025-02-20 10:15       ` Thomas Zimmermann
2025-02-20 10:48         ` Aditya Garg
2025-02-18  8:44 ` [PATCH 1/2] drm/format-helper: add helper for BGR888 to XRGB8888 conversion Thomas Zimmermann

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=858CA9AF-6128-4974-9C98-9EC01FF4FDB1@live.com \
    --to=gargaditya08@live.com \
    --cc=airlied@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=evepolonium@gmail.com \
    --cc=kekrby@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    /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

all inboxes | Powered by JetHome®